我一直在尝试使用 PHP 创建一个简单的联系表单。因此,我设法通过插入所有变量的值来使表单正常工作,并且它可以很好地发送电子邮件:
$to = "andrew@mingbogu.com";
$subject = "Job";
$message = "Test";
$from = "example@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
但是,只要我用 $_REQUEST[var] 替换这些值,电子邮件就会发送到我的垃圾邮件,没有发件人地址:
$to = "andrew@mingbogu.com";
$subject = "Job";
$message = $_REQUEST['clientMessage'];
$from = $_REQUEST['clientEmail'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $from";
mail($to,$subject,$message,$headers);
邮件截图:
我正在使用 jQuery 通过 ajax 表单获取值:
var clientName = $("#name").val();
window.alert(clientName);
var clientEmail = $("#email").val();
window.alert(clientEmail);
var clientMessage = $("#message").val();
window.alert(clientMessage);
var data = "from=" + clientEmail + "&subject=" + clientName + "&message=" + clientMessage;
$.ajax({
type: "POST",
url: "email.php",
data: data,
success: function() {
$("#loading").fadeOut(100).hide();
$("#name").val(' ');
$("#email").val(' ');
$("#message").val(' ');
$("#message-sent").fadeIn(100).show();
}
});
在将它们发送到 ajax 表单之前,我已经打印了clientName
,clientMessage
和 ,clientEmail
并且它们都以正确的值打印出来。知道我做错了什么吗?
HTML 表单:
<form id="contactMe" data-abide>
<input type="text" id="name">
<input type="text" id="email">
<textarea id="message"></textarea>
<button type="submit" id="sendEmail" class="button">Submit</button>