我已经使用这些参数配置了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/14257 e69sm88886wma.2 - gsmtp”在C:\第383行的wamp \ www \ mail \ swiftmailer \ lib \ classes \ Swift \ Transport \ AbstractSmtpTransport.php
2 回答
正如错误消息所示,
您需要授权将Gmail用于外部应用程序:转到https://www.google.com/settings/security/lesssecureapps然后将
Access for less secure apps
更改为enabled
.如果它仍然不起作用,您可以按照this page给出的建议 .
好的,我通过使用我的亲邮件解决了我的问题,而不是我的私人邮件