can't sign DKIM email from php with phpmailer -



have problem sending dkim signed email phpmailer (v 5.2.9).

the smtp server use (realsender.com) should sign every email send.
works when send email delphi program instead doesn't work php.

i've checked both email sent phpmailer , delphi https://www.mail-tester.com

the results 10/10 delphi , 6.8/10 php.

part of file send email phpmailer:

$mail = new phpmailer(); $mail->charset = 'utf-8'; $mail->setlanguage('it'); $mail->issmtp();  $mail->host = smtp_host; $mail->smtpauth = smtp_auth; $mail->username = smtp_username; $mail->password = smtp_password; if (defined('smtp_port')) {     $mail->port = smtp_port; } if (defined('smtp_secure')) {     $mail->smtpsecure = smtp_secure; } if(defined('dkim_domain')){     $mail->dkim_domain=dkim_domain;     $mail->dkim_selector=dkim_selector;     $mail->dkim_private=dkim_private; } [...]//setting from, to, subject , body $mail->send(); 

note: $mail->send(); return true.

firstly i've tried send email without setting dkim_ property , tried send they.
in both cases result invalid dkim sign , score of 6.8.

i have asked smtp support if know said may problem of phpmailer itself.

what can create dkim works?

thanks in advance.

update:
discovered problem in body of email.
i've stopped using dkim_ vars because smtp server automatically sign emails.
sending email empty, without tags or tags without text it's ok (9.9), otherwise score 6.8.
little html email (with links , divs) ok.
be?

i got it!
had split body of mail small chunks (for maximum of 990 characters per chunk), reason (explained here: http://permalink.gmane.org/gmane.mail.postfix.user/223780) is:

a cause of breakage sending application generates email incompatible rfc 5322 or rfc 5321 in respect.

lines longer 990.

the postfix smtp client keeps line length below smtp protocol limit of 1000 bytes including . since change happens after signing, break dkim signatures.

to avoid long-line curruption problems send mail in quoted-printable or base64 encoding, lines of @ 80 characters long.

this code i've used split string:

function create_html_email_from_string($str){     if(!is_string($str)){         return false;     }     return '<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"><html><body>'            .html_long_lines_split($str).'</body></html>'; }  /**  * function insert line endings (\r\n) after ending of <br>, <p> , <div> tags because if use chunk_split_unicode can break links , other tags , css.  */ function html_long_lines_split($str){     $str = str_ireplace(['<br>','<br/>','<br />'], "<br/>\r\n", $str);     $str = str_ireplace('</p>', "</p>\r\n", $str);     $str = str_ireplace('</div>', "</div>\r\n", $str);     //checks if there lines longer 990 bytes     $chunks=explode("\r\n", $str);     foreach ($chunks $k=>$c) {         if(strlen($chunks[$k])>990){             $chunks[$k]=chunk_split_unicode($chunks[$k], 500);         }     }     return implode("\r\n", $chunks); }  /**  * @link http://php.net/manual/en/function.chunk-split.php#107711<br>  */ function chunk_split_unicode($str, $l = 76, $e = "\r\n") {     $tmp = array_chunk(     preg_split("//u", $str, -1, preg_split_no_empty), $l);     $str = "";     foreach ($tmp $t) {         $str .= join("", $t) . $e;     }     return $str; }  //$mail instance of phpmailer $mail->msghtml(create_html_email_from_string($body)); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -