PHP Swift mailer: Failed to authenticate on SMTP u

2019-01-22 12:29发布

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 "user@example.com" using 2 possible authenticators

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

13条回答
疯言疯语
2楼-- · 2019-01-22 13:06

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.

查看更多
家丑人穷心不美
3楼-- · 2019-01-22 13:09

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"

查看更多
干净又极端
4楼-- · 2019-01-22 13:09

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

查看更多
放我归山
5楼-- · 2019-01-22 13:10

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.

查看更多
▲ chillily
6楼-- · 2019-01-22 13: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) [?]

查看更多
beautiful°
7楼-- · 2019-01-22 13:15

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 !

查看更多
登录 后发表回答