Reputation: 1194
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 protected]>\r\n" .
"Reply-To: [email protected]\r\n" .
"X-Mailer: PHP/" . phpversion();
$to = "[email protected]";
$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!
Upvotes: 4
Views: 2270
Reputation: 270607
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'];
// Use as a header when constructing the email
Message-Id: $message_id
Second message:
// Use the same value as these two headers when constructing the reply message.
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;
Upvotes: 7
Reputation: 69937
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.
Upvotes: 2
Reputation: 162781
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.
Upvotes: 1