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:29

You perhaps use the wrong username.

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

Example: JacekPL@lala.pl

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

查看更多
登录 后发表回答