How to fix Missing Message-ID in zend-mail

1k views Asked by At

I try to use zend-mail. I can send an email, but zend-mail didn't generate the message-id automatically, so I get this Message-Id:

<[email protected]>

when I check the original message.

so I've searched on Google & Zend-mail page and GitHub, but can't find how to add the message-id.

I tried this code to set the message-id:

require('vendor/zendframework/zend-mail/src/Header/MessageId.php');
use Zend\Mail\Header\MessageId;

$messid = new MessageId();
$messid->setId(); 

but still no message-id.

2

There are 2 answers

6
KevDev On

you can use getId() method see the method here in the source code. https://github.com/zendframework/zend-mail/blob/master/src/Header/MessageId.php#L88

this will return the id

$messid->getId(); 
0
Aliga Myway On

I've solved this problem, first, i need to clearallheaders like this

$message = new Message(); 
$message->getHeaders()->clearHeaders();

and set message-id after that