如果我使用以下代码,那么表单工作正常,我会将表单提交到我的电子邮件中。
<?php
if($_POST["submit"]) {
$recipient="meemail@gmail.com";
$subject="New request";
$headers = \'MIME-Version: 1.0\' . "\\r\\n";
$headers .= \'Content-type: text/html; charset=iso-8859-1\' . "\\r\\n";
$sender=$_POST["sendername"];
$senderEmail=$_POST["senderEmail"];
$message=$_POST["message"];
$name_title=$_POST["name_title"];
$mailBody = "<b>Name:</b> $name_title $sender\\n
<b>Email:</b> $senderEmail\\n\\n
<b>Message:</b> $message";
$mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
}
if ($mail_sent) {
?>
<p>Mail sent</p>
<?php } ?>
如果我更改
$mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
TO $mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>", $headers);
, 然后表单停止工作。问题是什么?
最合适的回答,由SO网友:TheDeadMedic 整理而成
From:
只是另一个邮件头。您需要将其与当前$headers
并将其作为一个参数传递给mail()
:
$headers = "From: $sender <$senderEmail>\\r\\n";
$headers .= "MIME-Version: 1.0\\r\\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\\r\\n";
// la de da
mail( $recipient, $subject, $mailBody, $headers );