【发布时间】:2016-03-15 10:53:28
【问题描述】:
我正在使用 Swiftmailer 和 Symfony 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