DKIM signing missing To header with default php mailer (mail())
A full-featured email creation and transfer class for PHP
Brought to you by:
coolbru
If this->mailer is set to 'mail', which is the default, then DKIM signing will generate a header where "To:" is missing, causing a hardfail.
Here's an example of the resulting header:
(...) DKIM-Signature: v=1; a=rsa-sha1; q=dns/txt; l=53; s=xxxxxxxxx; t=1363782841; c=relaxed/simple; h=From:To:Subject; d=xxxxxxxx.dk; z= | |Subject:=20First=20PHPMailer=20Message; (...)
It SHOULD read:
(...) DKIM-Signature: v=1; a=rsa-sha1; q=dns/txt; l=53; s=xxxxxxxxx; t=1363783226; c=relaxed/simple; h=From:To:Subject; d=xxxxxxxx.dk; z=From:=20Somebody=20<xxxxxx@xxxxx.dk> |To:=20xxxxxx@xxxxxx.dk |Subject:=20First=20PHPMailer=20Message; (...)
The reason is that the To header is removed in CreateHeader(), right before DKIM generation.
$this->MIMEHeader = $this->CreateHeader(); (...) $header_dkim = $this->DKIM_Add($this->MIMEHeader, ...
If you remove the conditional wrap:
if($this->Mailer != 'mail') { ... }
in CreateHeader(), then it will work but there'll be an extra To header (so it needs to be fixed in another way, so DKIM signing has access to the real headers).
Regards
Seph
Here's a patch that fixes it by appending the specific mail() headers needed for DKIM_Add to work.
1-liner.
Thanks for this report and patch. I've applied it on GitHub since the SF version is no longer maintained, see the SF project home page for more info.