[英]PHP mail function not working
我有一個發送電子郵件的php腳本。 看起來像這樣:
<?php
// subject
$subject = "$first_name $last_name has sent you a message on The Red-line";
// message
$message = "<html>
<head>
<title>
The Red-line
</title>
</head>
<body>
<p>
Hi $war_first,
</p> <br />
<p>
$first_name $last_name has sent you a message on the Red-line. To view your message, please login to <a href='www.thered-line.com'>the Red-line.</a>
</p> <br />
<p>
Sincerely,
</p> <br />
<p>
The Red-line Operator
</p>
</body>
</html>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "From: The Red-line messages@theredline.com \r\n";
$headers .= "To: $war_first $last_war <$war_mail>\r\n";
// Mail it
mail($war_mail, $subject, $message, $headers);
?>
當我在遠程服務器上對此進行測試時,我使用此腳本將電子郵件發送到我的收件箱:turbocapitalist1987@yahoo.com。 我收到了電子郵件,但“發件人”部分不起作用。 雅虎說我的電子郵件是從“ the@yahoo.com”發送的
有人知道為什么這不起作用嗎?
謝謝
對於From頭,用< >
括住實際地址:
$headers .= "From: The Red-line <messages@theredline.com> \r\n";
同時具有顯示名稱和電子郵件地址時,這是使用的正確格式 。 我猜測Yahoo會將第一個單詞“ The”解釋為整個電子郵件地址,並為該域提供了默認值(yahoo.com)。
<>
似乎是您的問題,應該是:
$headers .= "From: The Red-line <messages@theredline.com> \r\n";
其次,在Unix / Linux上,您必須在服務器上配置有效的MTA(即sendmail,postfix等),以直接中繼郵件或通過Smart Host中繼郵件。 如果您使用的是Windows,則必須在php.ini中配置SMTP服務器。
我建議使用預構建的PHP電子郵件庫,例如: http : //swiftmailer.org/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.