Get the email application to find out the response to php email

I can’t understand how to get the mail application (except for Google mail) to find out that the message was sent as “Answer to a question” and these emails are grouped together as one list of sent and sent messages.

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 it twice, I get two separate letters. Instead of one letter consisting of two letters.
Is there a way to combine them together, as one email responds to another, or am I doing something wrong?
I read the php mail () documentation and some web pages explaining how php mail works, and still cannot get emails to respond to each other.



Thanks for your time and help!

+4
source share
3 answers

Most email clients handle streams by looking at the Message-ID , In-Reply-To and References headers. In the first message, set the Message-ID header, then use the same value as the References and In-Reply-To headers. Email clients should group them by placing the original Message-ID and matching it with messages that have the associated References and In-Reply-To headers.

First post:

 // 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 post:

 // 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; 
+7
source

The response header is used to indicate that the response should be sent to a different email address than the one in the header.

I think that Google uses an algorithm to group messages together if the body part of the message contains text that was part of a message sent earlier or a reply to the message, or if the subject contains Re: and corresponds to a topic from another message group. But the response header probably does not affect the grouping of messages as a response.

+2
source

I do not see any problems here. Two letters sent the results in two letters received. This is the expected behavior. GMail combines them into a stream in the user interface, but even GMail treats them as two separate messages under the hood. All this is completely independent of the Reply-To header.

+1
source

Source: https://habr.com/ru/post/1384508/


All Articles