can';不要更改php邮件的地址

can';不要更改php邮件的地址,php,html,Php,Html,我正在尝试使用PHPmail从联系人表单发送电子邮件: <?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"

我正在尝试使用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.";       
   } 
?>

当主机覆盖
From:
标题时,您可以为邮件使用著名的第5个参数:

mail($to,$subject,$message,$headers,"-f your@email.here");

我真的建议您在某个时候尝试一下phpmailer或swiftmailer。

您正在这里覆盖$headers变量
$headers=“MIME-…
,将其更改为
$headers.=
,就像下面的itAh一样,谢谢。没有注意到。您可以使用php可用的50个优秀邮件库中的任何一个-phpmailer,switfmailer etcI只是忽略了一个句号,请参见上面的评论。@TricksfortheWeb啊,一切都很好。