PHPMailer : replace the default messageID

时光怂恿深爱的人放手 提交于 2020-01-15 03:44:10

问题


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 : http://phpmailer.github.io/PHPMailer/classes/PHPMailer.html#property_MessageID

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 :

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 ?


回答1:


The structure of MessageID should be:

<sometext@sometext>

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.



来源:https://stackoverflow.com/questions/39856450/phpmailer-replace-the-default-messageid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!