Question

I can't figure out how to get a mail application (except google mail) to recognize that an email was sent as a "Reply-To" and have those emails grouped together as one list of sent and replied emails.

For example, using php, if I use

$header = "From: Testing <email@mail.com>\r\n" .
                "Reply-To: email@mail.com\r\n" . 
                "X-Mailer: PHP/" . phpversion();

$to = "email@mail.com";

$message = "This is a reply";
$subject = "test 123";  
$success = mail($to, $subject, $message, $header);


And send this twice, I get two separate emails. Instead of one email composed of the two emails.
Is there a way to have them both grouped together as one email replied to another, or am I doing something wrong?
I've read the php mail() documentation and multiple webpages explaining how php mail works and still can't get the emails to reply to each other.

Thank you for your time and help!

Was it helpful?

Solution

Most mail clients handle threading by examining the Message-ID, In-Reply-To, and the References headers. In your first message, set a Message-ID header, then use the same value as the References and In-Reply-To headers. The mail clients should group them by placing locating the original Message-ID and matching it with messages having related References and In-Reply-To headers.

First message:

// Create a unique value for message id based on time, random value, and the hostname
$message_id = md5(time() . rand()) . $_SERVER['HTTP_HOST'];
Message-Id: $message_id

Second message:

// Use the same value as these two headers.
References: $message_id
In-Reply-To: $message_id
// Also, you should set a new unique message-id for this one
$new_message_id = md5(time() . rand()) . $_SERVER['HTTP_HOST'];
Message-ID: $new_message_id;

OTHER TIPS

The reply-to header is used to indicate a reply should be sent to a different email address than the one in the from header.

I think Google employs an algorithm to group messages together if part of the message body contains text that was part of a previously sent or replied to message, or if the subject contains Re: and matches a subject from another group of messages. But the reply-to header probably has no effect on grouping messages as a reply.

I see no problem here. Two emails sent results in two emails received. This is the expected behavior. GMail is grouping them together in a thread in the UI, but under the hood, even GMail treats these as two separate messages. This is all totally independent of the Reply-To header.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top