【问题标题】:Enable to send mails with Swiftmailer启用使用 Swiftmailer 发送邮件
【发布时间】:2016-03-15 10:53:28
【问题描述】:

我正在使用 SwiftmailerSymfony 2.8 将邮件从 gmail 帐户发送到 Outlook 帐户。 我在控制器中使用的代码:

$message = \Swift_Message::newInstance()
    ->setSubject('Test Email')
    ->setFrom('xxxxx@xxxxx.com')
    ->setTo('xxxxxx@outlook.com')
    ->setBody(
        $this->renderView(

            'QualifBundle:Mails:Welcome.html.twig'
            ),
        'text/html'
    );
$this->get('mailer')->send($message);

配置文件:

# Swiftmailer Configuration
swiftmailer:
    transport: %mailer_transport%
    encryption: %mailer_encryption%
    auth_mode:  %mailer_auth_mode%
    host:      %mailer_host%
    username:  %mailer_username%
    password:  %mailer_password%
    spool:     { type: memory }

参数yml:

mailer_username: xxxxxxx@gmail.com
mailer_password: xxxxxxxxx
mailer_transport:  smtp
mailer_encryption: ssl
mailer_auth_mode:  login
mailer_host: smtp.gmail.com

我设法解决了 SSL 错误,现在使用此代码,我的应用程序可以正常运行,但没有收到邮件(甚至可能没有发送) 我该如何解决或指纹?

更新 我删除了spool:{ type: memory },以便直接发送邮件,我得到了这个异常。

Connection could not be established with host 127.0.0.1 [Connection refused #111] 

我的主机应该是smtp.gmail.com 而不是localhost 知道吗?

解决方案 我通过入侵供应商的文件解决了我的问题,我知道这不是最好的解决方案,但至少我可以发送邮件。

StreamBuffer.php 中查找_establishSocketConnection() 函数应该在此路径中/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport 进入项目。 并添加以下几行以逃避 SSL 验证:

//...
$options = array();
if (!empty($this->_params['sourceIp'])) {
    $options['socket']['bindto'] = $this->_params['sourceIp'].':0';
}
//Add those two lines
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
//...

然后我重新启动了我发送邮件的浏览器,就像一个魅力一样

【问题讨论】:

    标签: php symfony email swiftmailer


    【解决方案1】:

    首先检查你的gmail帐户,你必须在你的gmail帐户中打开"Access for less secure apps"

    【讨论】:

    • 打开它..同样的结果
    【解决方案2】:

    解决方案 我通过入侵供应商的文件解决了我的问题,我知道这不是最好的解决方案,但至少我可以发送邮件。

    StreamBuffer.php 中查找_establishSocketConnection() 函数应该在此路径中/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport 进入项目。 并添加以下几行以逃避 SSL 验证:

    //...
    $options = array();
    if (!empty($this->_params['sourceIp'])) {
        $options['socket']['bindto'] = $this->_params['sourceIp'].':0';
    }
    //Add those two lines
    $options['ssl']['verify_peer'] = FALSE;
    $options['ssl']['verify_peer_name'] = FALSE;
    //...
    

    然后我重新启动了我发送邮件的浏览器,就像一个魅力一样

    【讨论】:

      【解决方案3】:

      另一种方式:

      $opt['ssl']['verify_peer'] = FALSE;
      $opt['ssl']['verify_peer_name'] = FALSE;
      
      $this->get('swiftmailer.mailer.default.transport.real')->setStreamOptions($opt);
      

      上面的代码要放在前面:\Swift_Message::newInstance()

      【讨论】:

        猜你喜欢
        • 2019-04-22
        • 2013-08-10
        • 1970-01-01
        • 1970-01-01
        • 2016-04-04
        • 2010-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多