george
george

Reputation: 462

How to prevent Gmail from stacking into a "conversation" emails sent via PHP mail()?

I have a web form which uses the following PHP code to send email:

$senderEmail = "[email protected]"
$senderName = "John Smith"

$noreplyEmail = "[email protected]"
$receiverEmail = "[email protected]"

$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);

The problem is that although each time $senderName, $senderEmail and $message are different in the inbox of the receiver (which is a Gmail domain inbox) the emails get stacked into a conversation by the Gmail's system.

What would be the proper way to prevent this stacking and receive them always as individual separate emails?

Upvotes: 0

Views: 560

Answers (1)

CodeBrauer
CodeBrauer

Reputation: 2925

Easy: You have to change the Subject of your email:

mail('[email protected]', 'Test', 'Hi there 3')

grouped message screenshot

mail('[email protected]', 'Test 3', 'Hi there 3')

seperate msg screenshot

Maybe something like $subject = "Contact from" . $senderName;

Upvotes: 3

Related Questions