【问题标题】:Why I have this error with swift mail php为什么我在使用 swift mail php 时出现此错误
【发布时间】: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 行

【问题讨论】:

  • 你有没有阅读错误信息?!

标签: php email


【解决方案1】:

好的,我通过使用我的专业邮件而不是我的个人邮件解决了我的问题

【讨论】:

    【解决方案2】:

    正如错误消息所说,

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

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

    如果还是不行,你可以按照this page上的建议去做。

    【讨论】:

    • @herbethadrien 您是否遵循了帮助页面上提供的其他建议?
    猜你喜欢
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 2022-10-04
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    相关资源
    最近更新 更多