php – Symfony SwiftMailer – 预期的响应代码220但是得到了代码“”,带有消息“”

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Symfony SwiftMailer – 预期的响应代码220但是得到了代码“”,带有消息“”脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
知道这个问题在SO上有很多像 this这样的答案,但是没有一个解决方案对我有用.

我正在尝试从我的GOOGLE Apps域发送邮件.大多数时间都会发送电子邮件,但有时会抛出此异常并且不会发送电子邮件.

Uncaught PHP Exception Swift_TransportException: "Expected response code 220 but got code "",wITh message """ at C:\HostingSpaces\abc\domain.COM\wwwroot\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.PHP line 383 {"exception":"[object] (Swift_TransportException(code: 0): ExPEcted response code 220 but got code \"\",with message \"\" at C:\\HostingSpaces\\abc\\domain.com\\wwwroot\\vendor\\swiftmailer\\swiftmailer\\lib\\classes\\Swift\\Transport\\AbstractSmtpTransport.PHP:383)"} []

是的,我使用SSL,是的,我已经允许访问不太安全的应用程序,是的我使用端口465.我已启用假脱机,以便应用程序不会崩溃,因为异常不会被捕获.

我的config.yML如下

swiftmailer:
    transport:  smtp
    host:       smtp.gmail.com
    username:   no-reply@googledomain.com
    password:   password
    port:       465
    encryption: ssl
    spool: { type: memory }

我的电子邮件课程如下

public function send_new_order_email($entity) {
    try{
        $message = $this->getEmailObj("toaddress@gmail.com");
        $message->setBody(
                $this->renderView(
                    'APIBundle:Emails:ops_neworder.html.twig',array('entity' => $entity)
                ),'text/html'
            )->setSubject('New Order : '.$entity->getId());

        $this->container->get('mailer')->send($message);
    }
    catch(Exception $e){}
}

PRivate function getEmailObj($email){
    $message = \Swift_Message::newInstance()
            ->setFrom('no-reply@googledomain.com')
            ->setTo($email);
    return $message;
}

你对这项工作有什么建议吗?

解决方法

在Symfony中,Swiftmailer是一个专门用于Gmail的配置,它处理电子邮件通信而忘记了其余的配置.这项工作对我来说很多次:

swiftmailer:
    transport: gmail
    username:  your_gmail_username
    password:  your_gmail_password

我希望这对你有意义

You have more information here

脚本宝典总结

以上是脚本宝典为你收集整理的php – Symfony SwiftMailer – 预期的响应代码220但是得到了代码“”,带有消息“”全部内容,希望文章能够帮你解决php – Symfony SwiftMailer – 预期的响应代码220但是得到了代码“”,带有消息“”所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。