Search code examples
phpimapgmail-imap

In Gmail In-Reply-To values are changed while replying through gmail


I have set the value for In-Reply-To to find the trail mail but while the user replying to that mail the value is changed

Example:

I am sending like below

'In-Reply-To: Testing value' ( the user also received with this text)

When user replying to this email. i have received like below

'In-Reply-To: <[email protected]>'

Please assist me i tried so many way but it failes

my code

$to      = 'XXXXXXXXXXXXX.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: XXXXXXXXXXXXX.com' . "\r\n" .
'Reply-To: p.XXXXXXXXXXXXX.com' . "\r\n" .
'In-Reply-To:testvalue';

mail($to, $subject, $message, $headers);

Solution

  • Yes, this is expected.

    In-Reply-To is expected to be set to the Message-Id of the message you're replying to; it does not preserve the previous value. So, it forms a linked-list:

    • Message Z with header In-Reply-To: Y is in reply to message with Message-Id: Y.
    • Message Y which will have its own In-Reply-To: X header referring to the message with Message-Id: X.
    • and so on.

    Since this breaks if you're missing any of the messages in the middle, the References header is the same idea, but more robust. It's a list of all messages that the message is in reply-to (capped to 10, generally), and should always have the root message (the first message in the conversation) as the first item. When you form a reply, add the Message-Id of the message you're replying to to the end of References header, and drop the second item until it is ten items long.

    Also, all these are defined to be Message-Ids, which should be enclosed in angle brackets, like <[email protected]>