Swift邮件程序不在服务器上工作但在本地机器上工作

时间:2016-02-24 07:56:01

标签: php outlook swiftmailer

我的代码是:

require_once 'Swift-5.0.3/lib/swift_required.php';

$transport = Swift_SmtpTransport::newInstance('smtp-mail.outlook.com', 587, "tls")
  ->setUsername('username@outlook.com')
  ->setPassword('password');

$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance('Test')
  ->setFrom(array('demo@gmail.com' => 'Dpu'))
  ->setTo(array('demo2@gmail.com'))
  ->setBody('test body');

$result = $mailer->send($message);
if($result)
echo "success";
else
echo "Failed";

代码正常工作,当我在本地计算机上工作时会发送邮件。但是在服务器中我收到错误并且没有发送邮件。

错误是:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "username@outlook.com" using 2 possible authenticators' in /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:184 Stack trace: #0 /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/EsmtpTransport.php(312): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) #1 /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/AbstractSmtpTransport.php(120): Swift_Transport_EsmtpTransport->_doHeloCommand() #2 /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3 /home/xxx/public_html/xxx/Mail/mail.php(19): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 184

请帮帮我......

0 个答案:

没有答案