启用使用 Swiftmailer 发送邮件
Enable to send mails with Swiftmailer
我正在使用 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;
//...
然后我重新启动了浏览器,我的邮件效果很好
首先检查您的 gmail 帐户,您必须在您的 gmail 帐户中打开 "Access for less secure apps"
解决方案
我通过侵入供应商的文件解决了我的问题,我知道这不是最好的解决方案,但至少我可以发送邮件。
在 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;
//...
然后我重新启动了浏览器,我的邮件效果很好
另一种方式:
$opt['ssl']['verify_peer'] = FALSE;
$opt['ssl']['verify_peer_name'] = FALSE;
$this->get('swiftmailer.mailer.default.transport.real')->setStreamOptions($opt);
上面的代码放在前面:\Swift_Message::newInstance()
我正在使用 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;
//...
然后我重新启动了浏览器,我的邮件效果很好
首先检查您的 gmail 帐户,您必须在您的 gmail 帐户中打开 "Access for less secure apps"
解决方案 我通过侵入供应商的文件解决了我的问题,我知道这不是最好的解决方案,但至少我可以发送邮件。
在 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;
//...
然后我重新启动了浏览器,我的邮件效果很好
另一种方式:
$opt['ssl']['verify_peer'] = FALSE;
$opt['ssl']['verify_peer_name'] = FALSE;
$this->get('swiftmailer.mailer.default.transport.real')->setStreamOptions($opt);
上面的代码放在前面:\Swift_Message::newInstance()