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!
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With