如何防止Gmail堆叠成通过PHP mail()发送的“对话”电子邮件?

时间:2017-02-03 13:55:36

标签: php email gmail

我有一个使用以下PHP代码发送电子邮件的网络表单:

$senderEmail = "sender@sender.com"
$senderName = "John Smith"

$noreplyEmail = "noreply@receiver.com"
$receiverEmail = "inbox@receiver.com"

$header = "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n";
$header .= 'From: "' . $senderName . '" <' . $noreplyEmail . ">\r\n";
$header .= 'Reply-To: "' . $senderName . '" <' . $senderEmail . ">";

$subject = "Contact form";
$message = "...";

mail($receiverEmail, $subject, $message, $header);

问题在于,虽然每次$senderName$senderEmail$message在收件人的收件箱(Gmail域收件箱)中有所不同,但电子邮件会堆叠在一起通过Gmail的系统。

什么是防止这种堆叠的正确方法,并将它们作为单独的单独电子邮件接收?

1 个答案:

答案 0 :(得分:3)

简单:您必须更改电子邮件的Subject

mail('hi@example.com', 'Test', 'Hi there 3')

grouped message screenshot

mail('hi@example.com', 'Test 3', 'Hi there 3')

seperate msg screenshot

也许像$subject = "Contact from" . $senderName;