2

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:<myname@domain.com>
2016-05-21 21:39:01 SERVER -> CLIENT: 554 5.7.1 <myname@domain.com>: Relay access denied
2016-05-21 21:39:01 SMTP ERROR: RCPT TO  command failed: 554 5.7.1 <myname@domain.com>: Relay access denied
2016-05-21 21:39:01 CLIENT -> SERVER: RCPT TO:<othername@domain.com>
2016-05-21 21:39:01 SERVER -> CLIENT: 554 5.7.1 <othername@domain.com>: Relay access denied
2016-05-21 21:39:01 SMTP ERROR: RCPT TO  command failed: 554 5.7.1 <othername@domain.com>: Relay access denied
SMTP Error: The following recipients failed: myname@domain.com, othername@domain.com
{"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 = "username@mydomain.fr";
$mail->Password = "mySMTPPassword";
$mail->addAddress('myname@domain.com');               // Name is optional
$mail->AddCC('othername@domain.com');
$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 !

Nolween Lopez
  • 53
  • 1
  • 8
  • http://stackoverflow.com/questions/17331718/relay-access-denied-on-sending-mail-other-domain-outside-of-network as i can see "relay access denied" few things to debug :- #1. change values of tls and port to ssl and normal and check each time #2. reverify your username and password and smtp host hope it helps :) – Ahmad May 21 '16 at 22:21

1 Answers1

0

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.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • While what I posted should work, I just checked on the code and it should pick a valid auth mechanism automatically. Are you using [the latest version of PHPMailer](https://github.com/PHPMailer/PHPMailer)? – Synchro May 22 '16 at 08:40
  • I 'm not using the last version of PHPMailer, that's also my bad, I use a version which has always succeded until now. I'm going to test with the latest version. The set of the AuthType doesn't display the Invalid authentication mechanism, thank you, I'll try with the latest version now and I wille tell you if it works. Thanks you again ! – Nolween Lopez May 22 '16 at 09:26