Symfony2 SwiftMailer Connection could not be established with host smtp.gmail.com

和自甴很熟 提交于 2019-12-06 05:10:37

If you want to use gmail for testing purpose your parameter.yml file should look like this

mailer_transport: gmail
mailer_host: null
mailer_user: email_address
mailer_password: 'password'

To use it in your Controller

    $messenger = \Swift_Message::newInstance();
    $messenger->setFrom(array("email_address" => "The name you want to be displayed "));

   $messenger->setTo(array($email1, $email2, ...));
   $messenger->setCc(array($email1, $email2, ...));      
   $messenger->setSubject($subject);
   $messenger->setBody($body, 'text/html');      
   $this->mailer->send($messenger);

For more information about sending email in symfony have a look here https://symfony.com/doc/current/email.html

Try deactivating your antivirus. Avast was blocking my send email action and Symfony 3 gave me that same error message!! hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!