Julien Julien - 18 days ago 4x
HTML Question

PHPMailer : replace the default messageID

I send emails using PHPMailer, evthg works well but I would to set a uniq MessageID for each email.

PHPMailer version : "v5.2.16"

(loaded with Composer from https://github.com/PHPMailer/PHPMailer.git)

I found the documentation here :

so here is what I tried :

$mail = new PHPMailer;
$mail->MessageID = md5('HELLO'.(idate("U")-1000000000).uniqid()).'-'.$type.'-'.$id.'@domain.com';

Result : This is always the default MessageID generated by PHPMailer :

enter image description here

and not mine... :(

Then I tried sthg more simple :

$mail->MessageID = "blablag@domain.com";

Result : KO (the same)

The documentation indicates that we can set a MessageID, and it should be a string, I don't understand at all why it doesn't work...

Any idea ?


The structure of MessageID should be:


If your MessageID doesn't have this exact structure - PHPMailer will ignore your MessageId and generate it's own MessageId.

You can change your code to:

$mail->MessageID = "<" . md5('HELLO'.(idate("U")-1000000000).uniqid()).'-'.$type.'-'.$id.'@domain.com>';

And it should work.