PHP Swift mailer: Failed to authenticate on SMTP using 2 possible authenticators
Asked Answered
C

13

26

When I send an email with the PHP Swift mailer to this server: smtp.exchange.example.com like this:

// Load transport
$this->transport =
    Swift_SmtpTransport::newInstance(
       self::$config->hostname,
       self::$config->port
    )
    ->setUsername(self::$config->username)
    ->setPassword(self::$config->password)
    ;

// Load mailer
$this->mailer = Swift_Mailer::newInstance($this->transport);

// Initialize message
$this->message = Swift_Message::newInstance();

// From
$this->message->setFrom(self::$config->from);

// Set message etc. ...

// Send
$this->mailer->send($this->message);

I get a strange error back:

Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators

I know for sure that the login-info is correct.

Cuneo answered 23/8, 2010 at 12:14 Comment(1)
Adding : encryption: ssl auth_mode: login solved the problem for me on SES.Halfprice
C
-8

Strange enough sending emails works again. We did not change anything and the host say they did not either. We think a server restarts or so. It is strange :S

Cuneo answered 25/8, 2010 at 12:17 Comment(3)
This is not a solution. I am getting this error for hours. I think it has something to do with 2-step verification.Aggressive
if it is because of the 2-Step Verification then you should define an App Password and use it as your password ! :)Raleigh
It should be a comment, not a possible solution to the problem.Pesade
Z
32

This might be old but somebody might get help through this. I too faced the same problem and received a mail on my gmail account stating that someone is trying to hack your account through an email client or a different site. THen I searched and found that doing below would resolve this issue.

Go to https://accounts.google.com/UnlockCaptcha‎ and unlock your account for access through other media/sites.

UPDATE : 2015

Also, you can try this, Go to https://myaccount.google.com/security#connectedapps At the bottom, towards right there is an option "Allow less secure apps". If it is "OFF", turn it on by sliding the button.

UPDATE : 2021

The google URL has now changed to : https://myaccount.google.com/lesssecureapps. You will be asked to relogin

Zootomy answered 18/12, 2013 at 11:26 Comment(1)
was searching about that error so long...Unlocking Captcha worked for me. Thank you sir!Consumptive
B
13

I had the same issue, so I've disabled one setting on my WHM root login, which is as follows :

WHM > Home > Server Configuration > Tweak Settings > Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) [?]

Brede answered 11/11, 2017 at 14:52 Comment(5)
This answer fix the problemTildi
This stopped the error message, still not getting emails though!!Turaco
Here you go. !!Preventer
Thank you so much for this answer! fixed my problem with a new cpanel server vpsIntroit
StackOverflow winning where tech-support is failing.Terri
D
8

I really have the same problem, finally, i solved it.

its likey not the Swift Mail's problem. It's Yaml parser's problem. if your password only the digits, the password senmd to swift finally not the same one.

swiftmailer:
    transport:  smtp
    encryption: ssl
    auth_mode:  login
    host:       smtp.gmail.com
    username:   your_username
    password:   61548921

you need fix it with double quotes password: "61548921"

Distracted answered 25/4, 2013 at 19:4 Comment(0)
L
4

I just received the same error.

The strange thing is that commented the credential lines

// ->setUsername(self::$config->username)
// ->setPassword(self::$config->password)

And the problem disappeared.

I'm puzzled because the mail server definitely needs those credentials.

Lillianalillie answered 16/10, 2012 at 19:19 Comment(2)
Hi @Sydwell, I have exact same thing - with commented lines the email is sending successfully. Did you find out why this is happenning?Cowpea
Hi @alex23, no, I have no clue. Its been while since I used this code.Lillianalillie
M
2

The server might require some kind of encryption and secure authentication.
see http://swiftmailer.org/docs/sending.html#encrypted-smtp

Mulberry answered 23/8, 2010 at 12:42 Comment(3)
This is not the problem, thanks anyway. I just emailed the host, i hope they can help me.Cuneo
this link is now deadTutankhamen
In my case, I had to specify: 'encryption'=>'tls' for it to work...Barracoon
K
2

I tried almost all the possible suggestions mention here but for me problem got solved after changing "Access for less secure apps" to ENABLE in my Google account security settings tab. Hope this might useful for others !

Kopp answered 17/10, 2014 at 17:1 Comment(1)
here is the link myaccount.google.com/security?hl=en&pli=1#connectedappsSams
O
1

try putting username in double quote "username", somehow that fixed for me.

Overline answered 30/1, 2014 at 21:29 Comment(0)
S
0

You perhaps use the wrong username.

I had a similar error. Ensure you're not using uppercase while logging into server.

Example: [email protected]

If you use ->setUsername('JacekPL'), this can cause an error. Use ->setUsername('jacekpl') instead. This solved my problem.

Sucre answered 29/10, 2012 at 10:40 Comment(0)
Y
0

I got the same same error.

I was using gmail account and Google's SMTP server to send emails. The problem was due to SMTP server refusing to authorize as it considered my web host (through whom I sent email) as an intruder.

I followed Google's process to identify my web host as an valid entity to send email through my account and problem was solved.

Younker answered 1/5, 2013 at 12:52 Comment(0)
H
0

I faced the same problem and solved it. Try to log in manually to your gmail account first. This issue is due to google has detected your gmail account has been abusing. E.g send a lot of emails over a short period of time.

Hod answered 27/6, 2013 at 4:1 Comment(0)
H
0

First check if there is any connectivity problem and you can reach the SMTP server:

In terminal type:

telnet servername portnumber 

If you receive the 220 response you can reach the SMTP server and there is no connectivity problem but if the connection to the server failed see what's wrong in your network.

If the server needs auth try to authenticate on the server by username and password and see if something goes wrong.

At last see if the server requires encryption and if yes openssl and other stuff are configured correctly.

Heinous answered 26/8, 2013 at 5:31 Comment(0)
F
0

If you are trying to send mail from your local enviroment eg. XAMPP or WAMP, this error will occur everytime, go ahead and try the same code on your web hosting or whatever you are using for production.

Also, 2 step authentication from google may be the issue.

Fairfax answered 26/4, 2015 at 23:55 Comment(0)
C
-8

Strange enough sending emails works again. We did not change anything and the host say they did not either. We think a server restarts or so. It is strange :S

Cuneo answered 25/8, 2010 at 12:17 Comment(3)
This is not a solution. I am getting this error for hours. I think it has something to do with 2-step verification.Aggressive
if it is because of the 2-Step Verification then you should define an App Password and use it as your password ! :)Raleigh
It should be a comment, not a possible solution to the problem.Pesade

© 2022 - 2024 — McMap. All rights reserved.