เราเขียน แบบนี้ ไครู้ บอกหน่อยน่ะค่ะ นั่ง งม ตั้งนานเลย
อันนี้ form ที่เราเขียน
<form id="frmRegister" class="form-horizontal" name="frmRegister" method="post" action="email-form.php" >
<div class="form-group col-sm-12">
<input type="text" id="inputFname" name="inputFname" class="form-control-contact" placeholder="* ชื่อ" value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputLname" name="inputLname" class="form-control-contact" placeholder="* นามสกุล"value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputPhone" name="inputPhone" class="form-control-contact" placeholder="* เบอร์โทรศัพท์"value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputEmail" name="inputEmail" class="form-control-contact" placeholder="* อีเมล์"value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputLine" name="inputLine" class="form-control-contact" placeholder="* Line id" value="" >
</div>
<div class="form-group">
<div class="btn-submit-box">
<input type="Submit" id="Submit" name="Submit" class="btn btn-default" onClick="js_onSubmitRegister()" value="ลงทะเบียน">
</div>
</div>
<input type="hidden" id="inputRefer" name="inputRefer" value="3" >
</form>
ส่วนอันนี้ email-form.php ที่เรา จะส่งค่าไปให้มัน
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "angmid033@gmail.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['inputFname']) ||
!isset($_POST['inputLname']) ||
!isset($_POST['inputPhone']) ||
!isset($_POST['inputEmail']) ||
!isset($_POST['inputLine'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$inputFname = $_POST['inputFname']; // required
$inputLname = $_POST['inputLname']; // required
$inputPhone = $_POST['inputPhone']; // required
$inputEmail = $_POST['inputEmail']; // not required
$inputLine = $_POST['inputLine']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$inputEmail)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$inputFname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$inputLname)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$inputPhone)) {
$error_message .= 'The PhoneNumber you entered does not appear to be valid.<br />';
}
if(strlen($inputLine) < 2) {
$error_message .= 'The Line ID you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$inputFname .= "First Name: ".clean_string($inputFname )."\n";
$inputLname .= "Last Name: ".clean_string($inputLname)."\n";
$inputPhone .= "Telephone: ".clean_string( $inputPhone)."\n";
$inputEmail .= "Email: ".clean_string($inputEmail)."\n";
$inputLine .= "Line ID : ".clean_string($$inputLine)."\n";
// create email headers
$headers = 'From: '.$inputEmail."\r\n".
'Reply-To: '.$inputEmail."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
ส่งค่า contact php ไปยัง email ยังไงค่ะ พอดี เขียนเเล้วไม่ส่งไปยัง Email ของเราอะค่ะ ทำไง!!!
อันนี้ form ที่เราเขียน
<form id="frmRegister" class="form-horizontal" name="frmRegister" method="post" action="email-form.php" >
<div class="form-group col-sm-12">
<input type="text" id="inputFname" name="inputFname" class="form-control-contact" placeholder="* ชื่อ" value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputLname" name="inputLname" class="form-control-contact" placeholder="* นามสกุล"value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputPhone" name="inputPhone" class="form-control-contact" placeholder="* เบอร์โทรศัพท์"value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputEmail" name="inputEmail" class="form-control-contact" placeholder="* อีเมล์"value="" >
</div>
<div class="form-group col-sm-12">
<input type="text" id="inputLine" name="inputLine" class="form-control-contact" placeholder="* Line id" value="" >
</div>
<div class="form-group">
<div class="btn-submit-box">
<input type="Submit" id="Submit" name="Submit" class="btn btn-default" onClick="js_onSubmitRegister()" value="ลงทะเบียน">
</div>
</div>
<input type="hidden" id="inputRefer" name="inputRefer" value="3" >
</form>
ส่วนอันนี้ email-form.php ที่เรา จะส่งค่าไปให้มัน
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "angmid033@gmail.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['inputFname']) ||
!isset($_POST['inputLname']) ||
!isset($_POST['inputPhone']) ||
!isset($_POST['inputEmail']) ||
!isset($_POST['inputLine'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$inputFname = $_POST['inputFname']; // required
$inputLname = $_POST['inputLname']; // required
$inputPhone = $_POST['inputPhone']; // required
$inputEmail = $_POST['inputEmail']; // not required
$inputLine = $_POST['inputLine']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$inputEmail)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$inputFname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$inputLname)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$inputPhone)) {
$error_message .= 'The PhoneNumber you entered does not appear to be valid.<br />';
}
if(strlen($inputLine) < 2) {
$error_message .= 'The Line ID you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$inputFname .= "First Name: ".clean_string($inputFname )."\n";
$inputLname .= "Last Name: ".clean_string($inputLname)."\n";
$inputPhone .= "Telephone: ".clean_string( $inputPhone)."\n";
$inputEmail .= "Email: ".clean_string($inputEmail)."\n";
$inputLine .= "Line ID : ".clean_string($$inputLine)."\n";
// create email headers
$headers = 'From: '.$inputEmail."\r\n".
'Reply-To: '.$inputEmail."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>