>我有一个表单,该表单在提交时会定向到一个aspx页面,该页面使用该表单的数据。在定向到上述页面之前,jquery 与 ajax 一起使用来检索表单值,并将所有内容发送到我的 php 电子邮件文件,该文件应该在提交表单时向我发送信息电子邮件。不幸的是,我什么也没收到,其他一切都有效,但我没有收到任何电子邮件。请帮忙,我不确定为什么这不起作用。
附加信息:我正在使用wordpress,并通过functions.php调用了jquery文件。php 文件通过 jquery 文件调用。
提前感谢!
网页表单
<form action="https://redirection_page.aspx" method="get" name="nform" id="nform">
<div class="submission">
<div class="fname">
<input type="text" name="firstName" class="fname" placeholder="First name" required="">
</div>
<br>
<div class="lname">
<input type="text" name="lastName" class="lname" placeholder="Last name" required="">
</div>
<br>
<div class="email">
<input type="email" name="email" class="email" placeholder="example@email.com" required="">
</div>
<br>
<div class="phone">
<input type="text" name="homePhone" class="phone" placeholder="Phone Number" required="">
</div>
<br>
<br>
<!-- Edit the Continue Text -->
<div class="form-button">
<input type='button' class="submit tp-button green big :hover.green" value="Continue">
</div>
</div>
</form>
Jquery/Ajax
jQuery(document).ready(function($) {
var nform = $('#nform');
$('#nform .form-button input.submit').click(function(){
var data = {
first : $("#nform input.fname").val(),
last : $("#nform input.lname").val(),
email : $("#nform input.email").val(),
phone : $("#nform input.phone").val(),
};
$.ajax({
type: "POST",
url: "/wp-content/themes/Avada/email.php",
data: data,
success: function(){
$('#nform').submit();
}
});
});
});
菲律宾邮政
<?php
if($_POST){
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$sendto = "myemailaddress@gmail.com";
$message = "";
$message .= "<p> Name: " . $first . " " . $last "</p>";
$message .= "<p> Email: " . $email . "</p>";
$message .= "<p> Phone Number: " . $phone . "</p>";
$mail = 'no-reply@'.str_replace('www.', '', $_SERVER['SERVER_NAME']);
$uniqid = md5(uniqid(time()));
$headers = 'From: '.$mail."'r'n";
$headers .= 'Reply-to: '.$mail."'r'n";
$headers .= 'Return-Path: '.$mail."'r'n";
$headers .= 'Message-ID: <'.$uniqid.'@'.$_SERVER['SERVER_NAME'].">'r'n";
$headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."'r'n";
$headers .= 'X-Priority: 3'."'r'n";
$headers .= 'X-MSMail-Priority: Normal'."'r'n";
$headers .= 'Content-Type: multipart/mixed;boundary="----------'.$uniqid.'"'."'r'n";
$headers .= '------------'.$uniqid."'r'n";
$headers .= 'Content-transfer-encoding: 7bit';
$headers .= 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
//send email
mail($sendto, "Apply Submission by " .$email, $message, $headers);
}
?>
尝试从mail.php
那里获得任何反馈,然后success
将触发:
...
//send email
mail($sendto, "Apply Submission by " .$email, $message, $headers);
header("Content-Type:text/html");
echo("ok");
}
?>
试试这个:
$.ajax({
type: "POST",
async: false,
url: "/wp-content/themes/Avada/email.php",
data: data,
success: function(){
window.location = "https://redirection_page.aspx/"
}
});
菲律宾邮政
if(mail($sendto, "Apply Submission by " .$email, $message, $headers)){
echo 'true';
}