I bit of a strange problem here. It looks like PHPMailer is connecting to my remote SMTP server and then decides to disconnect. Here's the code that I am using..
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->Host = 'mail.mydomain.co.uk';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]', 'My Domain - No Reply');
$mail->addAddress($client['email']);
$mail->addReplyTo($property['email']);
$mail->isHTML(true);
$mail->Subject = 'Message subject';
$mail->Body = $bodytexthtml;
$mail->AltBody = $bodytext;
And this is the debug message I get...
2016-08-15 13:02:53 Connection: opening to mail.mydomain.co.uk:587, timeout=300, options=array ( ) 2016-08-15 13:02:53 Connection: opened 2016-08-15 13:02:53 SERVER -> CLIENT: 220 mail.mailserver.com ESMTP Postfix (Debian/GNU) 2016-08-15 13:02:53 CLIENT -> SERVER: EHLO www.mydomain.co.uk 2016-08-15 13:02:53 SERVER -> CLIENT: 250-mail.mailserver.com 250-PIPELINING 250-SIZE 250-VRFY 250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN 2016-08-15 13:02:53 CLIENT -> SERVER: STARTTLS 2016-08-15 13:02:53 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2016-08-15 13:02:53 SMTP Error: Could not connect to SMTP host. 2016-08-15 13:02:53 CLIENT -> SERVER: QUIT 2016-08-15 13:02:53 SERVER -> CLIENT: MIA#�8~��;���>� �$܈#´�K��S�������w ]M��5��E�|8D��(����k>)N+.��S��D������S�M�I���l\x���D�Y=��Af&�#Q����'z��q�/($���Vc�G�#-/&�d��a�q�O!� �k�f"��pS���(��$�wEBS}y9s|��$]��a��|��ӾuE�(�����0Q��?��v��������>#M���4Kנ��'���W.�dž@(�#�PH.F�Sтs��\(�:U���b#�����d��9k��Y��Uk����I)a�N����>�+���O��8��X�WtM����F��6sL��n#�#!����_��e���z�v��^�t$B!J8�;�%�aAC�;����{��h%ۏ�D]FZ��`:\�R�F�{���ČH i@�B��d�(N�a�̅7�f ��(�n�݀���-�nt{��Au������NF��!E@��b��rW�5(+��p��sE�u����5N��g#4V��[��C�)��P�[g��OU�L[�@�c�H6���6_�C��Bu�� 2016-08-15 13:02:53 SMTP ERROR: QUIT command failed: MIA#�8~��;���>� �$܈#´�K��S�������w ]M��5��E�|8D��(����k>)N+.��S��D������S�M�I���l\x���D�Y=��Af&�#Q����'z��q�/($���Vc�G�#-/&�d��a�q�O!� �k�f"��pS���(��$�wEBS}y9s|��$]��a��|��ӾuE�(�����0Q��?��v��������>#M���4Kנ��'���W.�dž@(�#�PH.F�Sтs��\(�:U���b#�����d��9k��Y��Uk����I)a�N����>�+���O��8��X�WtM����F��6sL��n#�#!����_��e���z�v��^�t$B!J8�;�%�aAC�;����{��h%ۏ�D]FZ��`:\�R�F�{���ČH i@�B��d�(N�a�̅7�f ��(�n�݀���-�nt{��Au������NF��!E@��b��rW�5(+��p��sE�u����5N��g#4V��[��C�)��P�[g��OU�L[�@�c�H6���6_�C��Bu�� 2016-08-15 13:02:53 Connection: closed 2016-08-15 13:02:53 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
If I comment out "$mail->isSMTP();" then it works but does not send via my SMTP server.
Any idea where I should start to debug this?
Thanks.
Looks like I solved this one. The remote server was using an invalid certificate. I added this to my code and all works fine...
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
I'll leave it here in case anyone else runs into this.
As the docs say, while this stops the error messages, this is not a good solution - better to fix the certificate the server is using as otherwise it's just making you vulnerable to impersonation, forgery and MITM attacks.
Yes, good points Synchro.
I've updated the certificate on the server and removed the code but it was very useful for debugging.
Most helpful comment
Looks like I solved this one. The remote server was using an invalid certificate. I added this to my code and all works fine...
I'll leave it here in case anyone else runs into this.