我正在尝试使用PHP mail
从联系表单发送电子邮件:
<?php
$email = $_POST["email"];
$msg = $_POST["msg"];
$msg = nl2br($msg);
$msg = stripslashes($msg);
$headers = 'From: email@example.net' . "\r\n" .
'Reply-To: email@example.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to = "email@example.net";
$mseg = "<!DOCTYPE html><html><head></head><body style='font-family:sans-serif;'><div class='header' style='padding:20px;background:#dea544;border:2px inset #fff;'><h1>Tricks for the Web</h1></div><hr><div style='background:#dea;padding:1em'><p>$name contacted you. They left this message: </p><div class='msg-container' style='background:#fff;border:1px solid #000;padding:1.3em'><p class='msg' style='font-family:sans-serif;'>$msg</p></div></div></body></html>";
$subj = "Contact";
if(isset($_POST["copy"])){
$o = $_POST["email"];
$ss = "<!DOCTYPE html><html><head></head><body style='font-family:sans-serif;'><div class='header' style='padding:20px;background:#dea544;border:2px inset #fff;'><h1>Tricks for the Web</h1></div><hr><div style='background:#dea;padding:1em'><p>Thanks for contacting us. Here's your copy of that message you left us. </p><div class='msg-container' style='background:#fff;border:1px solid #000;padding:1.3em'><p class='msg' style='font-family:sans-serif;'>$msg</p></div></div></body></html>";
mail($to, $subj, $mseg,$headers);
mail($o, $subj, $ss, $headers);
echo "Your message was submitted successfully. Please note that your copy may take time to reach you.";
} else {
mail($to, $subj, $mseg, $headers);
echo "Your message was submitted successfully.";
}
?>
电子邮件会被发送,但是从地址仍然是默认地址,它不是我设置的地址。为什么这不起作用,我该如何解决这个问题
的 Reference
的 Live Page
答案 0 :(得分:2)
当主持人覆盖From:
标题时,您可以使用着名的第五个参数邮件:
mail($to,$subject,$message,$headers,"-f your@email.here");
我真的建议在某些时候尝试给phpmailer或swiftmailer。