 |
|
ผมสร้างform เพื่อส่ง ข้อมูล ไปยังemail ที่กำหนดไว้ ระบบแจ้งเตือนว่าข้อมูลได้ถูกส่งไปแล้ว แต่พอเช็คอีเมล์ ไม่มีข้อมูลที่ส่งเข้าไปครับ อยากทราบว่าผมต้องแก้ไขตรงจุดไหนเพิ่มครับผม
ขอบคุณครับ
formsend.php
<form id="contact-form" method="post" action="request-a-demo-contact.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="form_propertyname" style="color: #49c5b6;">Property Name *</label>
<input id="form_property" type="text" name="propertyname" class="form-control" placeholder="Please enter your firstname *" required="required"
data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="form_propertytype" style="color: #49c5b6;">Property Type *</label>
<select name="propertytype" id="propertytype" class="form-control" aria-required="true" aria-invalid="false" required="required">
<option value="">Please Select Your Property Type</option>
<option countryid="1" value="Hotel">Hotel</option>
<option countryid="2" value="Resort">Resort</option>
<option countryid="3" value="Guest_House">Guest House</option>
<option countryid="4" value="Bed_and_Breakfast">Bed and Breakfast</option>
<option countryid="5" value="Hostel">Hostel</option>
<option countryid="6" value="Boutique">Boutique</option>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="form_name" style="color: #49c5b6;">First name *</label>
<input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your firstname *" required="required"
data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="form_lastname" style="color: #49c5b6;">Last name *</label>
<input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Please enter your lastname *" required="required"
data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="form_email" style="color: #49c5b6;">Email *</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your email *" required="required"
data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="form_phone" style="color: #49c5b6;">Phone*</label>
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<center><div class="g-recaptcha" data-sitekey="6Lf5DR4UAAAAABfnuo5l1EhGAhsiLqXRa_R4Vveq" data-callback="verifyRecaptchaCallback" data-expired-callback="expiredRecaptchaCallback">
</div></center>
</div>
<center><input type="submit" class="btn btn-success btn-send" value="Send message"></center>
</div>
</div>
</form>
ส่งค่าไปที่
request-a-demo-contact.php
<?php
// require ReCaptcha class
require('recaptcha-master/src/autoload.php');
// configure
// an email address that will be in the From field of the email.
$from = $_POST[email];
// an email address that will receive the email with the output of the form
$sendTo = '[email protected]';
// subject of the email
$subject = $_POST[propertyname];
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('propertytype' => 'Propertytype', 'name' => 'Name', 'surname' => 'Surname', 'email' => 'Email', 'phone' => 'Phone', );
// message that will be displayed when everything is OK :)
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
// ReCaptch Secret
$recaptchaSecret = '6Lf5DR4UAAAAACArH2pC8uW4BRSUjBILYQnz_u9f';
// let's do the sending
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try {
if (!empty($_POST)) {
// validate the ReCaptcha, if something is wrong, we throw an Exception,
// i.e. code stops executing and goes to catch() block
if (!isset($_POST['g-recaptcha-response'])) {
throw new \Exception('ReCaptcha is not set.');
}
// do not forget to enter your secret key from https://www.google.com/recaptcha/admin
$recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret, new \ReCaptcha\RequestMethod\CurlPost());
// we validate the ReCaptcha field together with the user's IP address
$response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$response->isSuccess()) {
throw new \Exception('ReCaptcha was not validated.');
}
// everything went well, we can compose the message, as usually
$emailText = "You have a new message from your contact form\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
} catch (\Exception $e) {
$responseArray = array('type' => 'danger', 'message' => $e->getMessage());
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
} else {
echo $responseArray['message'];
}
Tag : PHP, HTML, CSS, HTML5, jQuery
|
|
 |
 |
 |
 |
Date :
2019-02-07 17:01:50 |
By :
bakerylove |
View :
544 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |