Home » Php » Configure PHPMailer to work with exchange

Configure PHPMailer to work with exchange

Posted by: admin October 26, 2017 Leave a comment

Questions:

I am using phpmailer from some months on a customer server but the “mail provider” changed its server to use Exchange and since there phpmailer stopped working I tried several parameters but it never work.

My actual configuration:

    $mail = new PHPMailer(true);
    $mail->IsSMTP();
    $mail->SMTPDebug=4;
    $mail->CharSet = "UTF-8";
    $mail->Timeout = 10;
    $mail->IsHTML(true);
    $mail->Host='smtp.fingerprint.fr';
    $mail->Port = 465; 
    $mail->Username = 'username';
    $mail->Password = 'password';
    $mail->SMTPAuth = true; 
    $mail->AuthType = 'LOGIN';
    $mail->SMTPSecure = 'ssl';

    $mail->SMTPOptions = array (
        'ssl' => array(
                        'verify_peer'  => false,
                        'verify_peer_name'  => false,
                        'allow_self_signed' => true));

    $mail->Priority = 3;

    $mail->setFrom('[email protected]', 'name');
    $mail->AddAddress($email); // destinataire

    $mail->Subject=$objet;
    $mail->Body=$message;
    $mail->WordWrap = 50;

    $mail->send();

    $mail->SmtpClose();

With port 465, after several seconds I get:

2017-10-25 08:11:18 Connection: opening to ssl://smtp.fingerprint.fr:465, timeout=10, options=array (
                                        'ssl' => 
                                        array (
                                          'verify_peer' => false,
                                          'verify_peer_name' => false,
                                          'allow_self_signed' => true,
                                        ),
                                      )
2017-10-25 08:11:19 Connection: opened
2017-10-25 08:11:19 SMTP -> get_lines(): $data is ""
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "220 mxr1.fingerprint.fr ESMTP
                                      "
2017-10-25 08:11:19 SERVER -> CLIENT: 220 mxr1.fingerprint.fr ESMTP
2017-10-25 08:11:19 CLIENT -> SERVER: EHLO domain.tld
2017-10-25 08:11:19 SMTP -> get_lines(): $data is ""
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "250-mxr1.fingerprint.fr
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "250-AUTH LOGIN CRAM-MD5 PLAIN
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr
                                      250-AUTH LOGIN CRAM-MD5 PLAIN
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "250-AUTH=LOGIN CRAM-MD5 PLAIN
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr
                                      250-AUTH LOGIN CRAM-MD5 PLAIN
                                      250-AUTH=LOGIN CRAM-MD5 PLAIN
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "250-PIPELINING
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr
                                      250-AUTH LOGIN CRAM-MD5 PLAIN
                                      250-AUTH=LOGIN CRAM-MD5 PLAIN
                                      250-PIPELINING
                                      "
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "250 8BITMIME
                                      "
2017-10-25 08:11:19 SERVER -> CLIENT: 250-mxr1.fingerprint.fr
                                      250-AUTH LOGIN CRAM-MD5 PLAIN
                                      250-AUTH=LOGIN CRAM-MD5 PLAIN
                                      250-PIPELINING
                                      250 8BITMIME
2017-10-25 08:11:19 Auth method requested: LOGIN
2017-10-25 08:11:19 Auth methods available on the server: LOGIN,CRAM-MD5,PLAIN
2017-10-25 08:11:19 CLIENT -> SERVER: AUTH LOGIN
2017-10-25 08:11:19 SMTP -> get_lines(): $data is ""
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "334 Vqsdfg5fgqU6
                                      "
2017-10-25 08:11:19 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2017-10-25 08:11:19 CLIENT -> SERVER: xxx
2017-10-25 08:11:19 SMTP -> get_lines(): $data is ""
2017-10-25 08:11:19 SMTP -> get_lines(): $str is  "334 Uqgsh3dvcmQ6
                                      "
2017-10-25 08:11:19 SERVER -> CLIENT: 334 x32d13f1321
2017-10-25 08:11:19 CLIENT -> SERVER: xxx=
2017-10-25 08:11:29 SMTP -> get_lines(): $data is ""
2017-10-25 08:11:29 SMTP -> get_lines(): $str is  ""
2017-10-25 08:11:29 SMTP -> get_lines(): timed-out (10 sec)
2017-10-25 08:11:29 SERVER -> CLIENT:
2017-10-25 08:11:29 SMTP ERROR: Password command failed:
2017-10-25 08:11:29 SMTP Error: Could not authenticate.
2017-10-25 08:11:29 CLIENT -> SERVER: QUIT
2017-10-25 08:11:29 SMTP -> get_lines(): $data is ""
2017-10-25 08:11:29 SMTP -> get_lines(): $str is  "535 authorization failed (#5.7.0)
                                      "
2017-10-25 08:11:29 SERVER -> CLIENT: 535 authorization failed (#5.7.0)
2017-10-25 08:11:29 SMTP ERROR: QUIT command failed: 535 authorization failed (#5.7.0)
2017-10-25 08:11:29 Connection: closed
2017-10-25 08:11:29 SMTP Error: Could not authenticate.

With port 587, TLS

Connection: opening to smtp.fingerprint.fr:587, timeout=10, options=array ()
Connection: opened
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "220 mxr1.fingerprint.fr ESMTP"
SERVER -> CLIENT: 220 mxr1.fingerprint.fr ESMTP
CLIENT -> SERVER: EHLO creforma.fr
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250-mxr1.fingerprint.fr"
SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr"
SMTP -> get_lines(): $str is "250-AUTH LOGIN CRAM-MD5 PLAIN"
SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr250-AUTH LOGIN CRAM-MD5 PLAIN"
SMTP -> get_lines(): $str is "250-AUTH=LOGIN CRAM-MD5 PLAIN"
SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr250-AUTH LOGIN CRAM-MD5 PLAIN250-AUTH=LOGIN CRAM-MD5 PLAIN"
SMTP -> get_lines(): $str is "250-PIPELINING"
SMTP -> get_lines(): $data is "250-mxr1.fingerprint.fr250-AUTH LOGIN CRAM-MD5 PLAIN250-AUTH=LOGIN CRAM-MD5 PLAIN250-PIPELINING"
SMTP -> get_lines(): $str is "250 8BITMIME"
SERVER -> CLIENT: 250-mxr1.fingerprint.fr250-AUTH LOGIN CRAM-MD5 PLAIN250-AUTH=LOGIN CRAM-MD5 PLAIN250-PIPELINING250 8BITMIME
CLIENT -> SERVER: STARTTLS
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "502 unimplemented (#5.5.1)"
SERVER -> CLIENT: 502 unimplemented (#5.5.1)
SMTP ERROR: STARTTLS command failed: 502 unimplemented (#5.5.1)
SMTP Error: Could not connect to SMTP host.
CLIENT -> SERVER: QUIT
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "221 mxr1.fingerprint.fr"
SERVER -> CLIENT: 221 mxr1.fingerprint.fr
Connection: closed
SMTP Error: Could not connect to SMTP host.

Can someone help ?
Thanks

Answers: