我試圖使用PHP mail
從一個接觸的形式發送電子郵件:不能從地址PHP的郵件更改
<?php
$email = $_POST["email"];
$msg = $_POST["msg"];
$msg = nl2br($msg);
$msg = stripslashes($msg);
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\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 protected]";
$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
你在這裏覆蓋你的$ headers變量'$ headers =「MIME -...',把它改爲'$ headers。='就像你有它下面那樣 – rjdown
啊,謝謝。沒有注意到。 – TricksfortheWeb
你可以使用任何50個優秀的郵件庫可用於PHP - phpmailer,switfmailer等 –