簡體   English   中英

PHP郵件未發送-標頭設置不正確?

[英]PHP mail isn't sending - headers set incorrectly?

之前,我已經使用PHP的mail()函數成功發送了郵件,對於密碼重置通知電子郵件,我復制了在其他地方使用的語法,但是我想我搞砸了它,因為它沒有到達目的地。 這是我正在使用的代碼:

$headers = 'To:'.$email."\r\n";
$headers .= 'From: webmaster@aromaclear.co.uk'."\r\n";
$to = $email."\r\n";
$subject = 'AromaClear Password Reset Notification'. "\r\n";
$msg = 'From: AromaClear'."\r\n";
$msg .='Subject: Your New Password'. "\r\n";
$msg .= 'Message: Your new password is '.$newpass."\r\n";
$msg.= 'If you have received this e-mail in error, please ignore it.'. "\r\n";

mail($to, $subject, $msg, $headers);

有什么想法嗎?

嘗試查看服務器的郵件日志,以了解為什么它不被轉發。 例如,可能是該服務器的sendmail想要-F標志作為From頭,而不是在頭文本中指定它。

mail($to, $subject, $msg, $headers, "-f $from");

另外,您似乎在做很多額外的/怪異的工作。 這要容易得多:

$subject = "AromaClear Password Reset Notification";
$headers = "From: webmaster@aromaclear.co.uk";
$msg = "Your new password is $newpass\r\nIf you have received this e-mail in error, please ignore it.\r\n.";

if(mail($email, $subject, $msg, $headers))
{
  //handle success
}
else
{
  //handle failure
}

根據您的喜好更改樣式。

您檢查過mail()的返回值了嗎? 如果不是FALSE,則表示可以接受,並且代碼還可以,但是其他地方有些混亂。

對我來說很好,也許

if (mail($to_email,$subject,$message, $headers))
    echo 'Success';
else
    echo 'Error';
}

這可能會讓您知道它是否正在嘗試發送。

只是不要在各處添加“ \\ r \\ n”,僅將其用於分隔標題。 在消息中,您只能使用\\ n,它將起作用。 並且在主題和接收者的末尾,不需要“ \\ r \\ n”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM