您好我正在尝试从数据作为电子邮件发送。我正在使用 PHP mail() 发送电子邮件并使用 Ajax 提交数据以避免页面重新加载。提交表单时未发送电子邮件。我究竟做错了什么?代码有点像这样。
阿贾克斯:
$('#submit').click(function(){
$.ajax({
url: test.php,
type:'POST',
success: function(msg){
alert('Email Sent');
}
});
});
HTML 表单:
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td>*Your name:</td>
<td><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">*Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" id="submit" value="Send"></td>
</tr>
</table>
php:
<?php
if ($_POST["email"]<>'') {
$ToEmail = 'somugus@gmail.com';
$EmailSubject = 'Fusio Dose customer info';
//$mailheader = "From: ".$_POST["email"]."\r\n";
//$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
//$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."\r\n";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."\r\n";
$MESSAGE_BODY .= "Primary: ".$_POST["primary"]."\r\n";
$MESSAGE_BODY .= "Sedcondary: ".$_POST["secondary"]."\r\n";
//$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
工作示例在这里