Search code examples
smtpphpmailer

PHPMailer - Invalid authentication mechanism


I need you for a problem that I have with my PHPMailer settings : each time I got this issue :


In my response into the browser :

> 2016-05-21 21:39:01   SERVER -> CLIENT: 220 *****.*****.com ESMTP Postfix
2016-05-21 21:39:01 CLIENT -> SERVER: EHLO www.mysite.fr
2016-05-21 21:39:01 SERVER -> CLIENT: ***.***.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
2016-05-21 21:39:01 CLIENT -> SERVER: STARTTLS
2016-05-21 21:39:01 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2016-05-21 21:39:01 CLIENT -> SERVER: EHLO www.mysite.fr
2016-05-21 21:39:01 SERVER -> CLIENT: *****.*****.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
2016-05-21 21:39:01 CLIENT -> SERVER: AUTH LOGIN
2016-05-21 21:39:01 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: Invalid authentication mechanism
2016-05-21 21:39:01 SMTP ERROR: AUTH command failed: 535 5.7.8 Error: authentication failed: Invalid authentication mechanism
2016-05-21 21:39:01 CLIENT -> SERVER: RSET
2016-05-21 21:39:01 SERVER -> CLIENT: 250 2.0.0 Ok
2016-05-21 21:39:01 CLIENT -> SERVER: MAIL FROM:<root@localhost>
2016-05-21 21:39:01 SERVER -> CLIENT: 250 2.1.0 Ok
2016-05-21 21:39:01 CLIENT -> SERVER: RCPT TO:<[email protected]>
2016-05-21 21:39:01 SERVER -> CLIENT: 554 5.7.1 <[email protected]>: Relay access denied
2016-05-21 21:39:01 SMTP ERROR: RCPT TO  command failed: 554 5.7.1 <[email protected]>: Relay access denied
2016-05-21 21:39:01 CLIENT -> SERVER: RCPT TO:<[email protected]>
2016-05-21 21:39:01 SERVER -> CLIENT: 554 5.7.1 <[email protected]>: Relay access denied
2016-05-21 21:39:01 SMTP ERROR: RCPT TO  command failed: 554 5.7.1 <[email protected]>: Relay access denied
SMTP Error: The following recipients failed: [email protected], [email protected]
{"actif":0,"result":"activ\u00e9","retour":4}2016-05-21 21:39:01    CLIENT -> SERVER: QUIT
2016-05-21 21:39:01 SERVER -> CLIENT: 221 2.0.0 Bye

Here is my PHP Settings :

        $mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->CharSet    = 'UTF-8';
$mail->SMTPSecure = 'tls';
$mail->Host = "mail.host.com";
$mail->Port = 587;
$mail->Username = "[email protected]";
$mail->Password = "mySMTPPassword";
$mail->addAddress('[email protected]');               // Name is optional
$mail->AddCC('[email protected]');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject ';
$mail->Body    = $messageactif;

if(!$mail->send()) {
    $data['return'] = 4;
    echo json_encode($data);
    die();
} else {
    $data["return"] = 1;
}

I don't understand why i get an Invalid authentication mechanism.

I tried to set an acount with Thunderbord and these SMTP Username, password, host and port, and it works !

Has anybody an idea?

Thank you !


Solution

  • Your server's login mechanisms don't include the default LOGIN type - notice in the SMTP capability list it says only:

    250-AUTH PLAIN
    

    So you need to set:

    $mail->AuthType = 'PLAIN';
    

    Do not turn off TLS verification!

    You're getting the relay access denied error because it's carrying on trying to send to the other recipients even though you've not authenticated, and you can't usually send through a server (i.e. 'relay') without authentication, otherwise you'd be an open relay, which is a bad thing. It's nothing to do with ports or security settings. It's probably a bug that PHPMailer doesn't just quit after failing auth.