Exim not adding Message-ID and Date headers when sending via PHP & Pear Mail factory

Operating System & Version
CentOS 7
cPanel & WHM Version
v90.0.15

liebn0r

Member
Dec 7, 2017
12
1
3
USA
cPanel Access Level
Website Owner
The following is my code for sending mail with PHP (within the context of a custom Email class). If I change the first parameter of Mail::factory() to 'mail', Exim will add the Message-ID and Date headers, but as 'smtp' it does not. I don't want to use the 'mail' setting because it causes X-PHP headers to get added which cannot be disabled without forking the cpanel module from github which is a little out of the scope of what I'm trying to accomplish here. Any ideas as to why the 'smtp' option causes Exim to not add the missing headers? I can generate my own Message-ID and Date headers in PHP, but the Message-ID won't match Exim's internal Message-ID for the email and I'm worried that will cause consistency issues within Exim's general mail management.

PHP:
// Send locally
require_once('Mail.php');
require_once('Mail/mime.php');

$headers = array(
    'From' => $this->fromName . ' <' . $this->fromEmail . '>',
    'To' => implode(", ", $this->recipients),
    'Subject' => $this->title
);

$mime = new Mail_mime("\n");

if( $this->useHtml || $this->useStandardTemplate ) {

    $mime->setHTMLBody($message);
 
} else {
 
    $mime->setTXTBody($message);
 
}

$body = $mime->get(array(
    'text_encoding' => '7bit',
    'text_charset' => 'UTF-8',
    'html_charset' => 'UTF-8',
    'head_charset' => 'UTF-8'
));
$headers = $mime->headers($headers);

$mail = &Mail::factory('smtp');
$mail->send( $this->recipients, $headers, $body );
 

cPanelChris

Moderator
Staff member
Feb 16, 2020
38
4
8
Houston, TX
cPanel Access Level
Root Administrator
Hello @liebn0r ,

The mail client can generate the message-id. It must be globally unique though as described here. Something like the following should be unique.

PHP:
$message-id = time() .'-' . md5($sender . $recipient) . '@' $_SERVER['SERVER_NAME'];
That said, Exim should generate one if it's not present. This is described in section 12 of the following Exim message processing documentation.
 

liebn0r

Member
Dec 7, 2017
12
1
3
USA
cPanel Access Level
Website Owner
Yeah, I can't figure out why Exim isn't generating the missing headers for this method of sending email, but it is for others. I even tried adding the custom ACL rules as described in some other thread around here.

I guess I'll just add the headers in PHP and hope it doesn't cause any issues.