首页 文章

为什么我有swift邮件php这个错误

提问于
浏览
0

我已经使用这些参数配置了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 回答

  • 1

    正如错误消息所示,

    535-5.7.8不接受用户名和密码

    您需要授权将Gmail用于外部应用程序:转到https://www.google.com/settings/security/lesssecureapps然后将 Access for less secure apps 更改为 enabled .

    如果它仍然不起作用,您可以按照this page给出的建议 .

  • 0

    好的,我通过使用我的亲邮件解决了我的问题,而不是我的私人邮件

相关问题