问题即将到来
"Connection could not be established with host localhost [No connection could be made because the target machine actively refused it. #10061]"
config_dev.yml:
swiftmailer:
transport: gmail
username: '***'
password: '****'
host: 'smtp.gmail.com'
auth_mode: 'login'
encryption: 'ssl'
config_test.yml
swiftmailer:
disable_delivery: false //previously it was set it true
发送电子邮件的symfony2代码
public function sendEmail($data = array())
{
try{
$mailer = $this->Container->get('mailer');
$message = $mailer->createMessage()
->setSubject($data['subject'])
->setFrom($data['fromEmail'])
->setTo($data['toEmail'])
->setBody($data['body'], 'text/html');
if (array_key_exists('attachmentPath', $data) && $data['attachmentPath'] !== null) {
$message->attach(\Swift_Attachment::fromPath($data['attachmentPath']));
}
return $mailer->send($message); //returns true or false upon success
}catch(\Exception $e){
throw new \Exception('Exception occurred :- '.$e->getMessage(), 500);
}
}
网址:http://symfony.com/doc/current/email/gmail.html
另一个网址:https://github.com/symfony/swiftmailer-bundle/issues/106
请提示是否有任何遗漏
parameters.yml
parameters:
database_driver: pdo_oci
database_host: ***
database_port: 1521
database_name: **
database_user: ***
database_password: **
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: '***'
mailer_password: '***'
是database_port:1521是否会产生问题?
对我有用的解决方案
swiftmailer:
transport: smtp
host: ***
port: 25
logging: true
username: smtp
password: ***
delivery_address: ****
答案 0 :(得分:0)
最近我遇到了类似的问题:无法从Gmail帐户发送电子邮件。
在我的情况下,它是一个VB应用程序,所以我真的不知道这是否相关,但最终解决它的是将端口设置为587(tls可能是465)然后允许访问来自Gmail帐户的“安全性较低的应用程序”(here是如何操作的,如果需要的话)。
您的config_dev.yml将是这样的:
swiftmailer:
transport: gmail
username: '***'
password: '****'
host: 'smtp.gmail.com'
auth_mode: 'login'
encryption: 'ssl'
port: '587'