【发布时间】:2016-10-25 19:14:59
【问题描述】:
我已经使用这些参数配置了 SwiftMailer,但是当我尝试发送邮件时出现错误。
代码:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587,'tls')
->setUsername('mail@gmail.com')
->setPassword('password');
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
Swift::init('swiftmailer_configurator');
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject($sujet)
// Set the From address with an associative array
->setFrom(array('Mail@mail.com' => 'Site Mail'))
// Set the To addresses with an associative array
->setTo(array($mail))
// Give it a body
->setBody($texte)
// And optionally an alternative body
->addPart("<q>$texte</q>", 'text/html');
// Send the message
if ($mailer->send($message)) {
echo "Sent";
} else {
echo "Failed";
}
结果:
致命错误:未捕获的异常“Swift_TransportException”与 消息 C:\wamp\www\mail\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php 在第 383 行(!)Swift_TransportException:预期的响应代码 250 但得到代码“535”,消息“535-5.7.8 用户名和密码不是 公认。在 535 5.7.8 了解更多信息 https://support.google.com/mail/answer/14257e69sm88886wma.2 - gsmtp " 在 C:\wamp\www\mail\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php 在第 383 行
【问题讨论】:
-
你有没有阅读错误信息?!