SwiftMailer + Gmail - Cannot send email

馋奶兔 提交于 2019-11-30 16:22:33

First login with your account and open this in new tab,

https://www.google.com/settings/u/1/security/lesssecureapps
https://accounts.google.com/b/0/DisplayUnlockCaptcha
https://security.google.com/settings/security/activity?hl=en&pli=1

you need to make sure your using email id has enable for less secure apps.

You can send mail by using tls instead of ssl certificate like below:

    $transport =  Swift_SmtpTransport::newInstance('smtp.gmail.com', 587,'tls')
                            ->setUsername('email@gmail.com')
                            ->setPassword('mypasss');

    $mailer = Swift_Mailer::newInstance($transport);

    $message = Swift_Message::newInstance('Contato via Site')
            ->setFrom(array($email => $de))
            ->setTo(array($destinatario => 'Agência Linka'))
            ->setBody($corpo_mensagem, 'text/html')
            ->setCharset('UTF-8');

    $mailer->send($message);
Franco

Gmail has changed his policy so yuo will need to take special additional steps to make this working, I could explain it here for you but You can have a look at this answer which explains the action you need to take:

Using php's swiftmailer with gmail

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