Yii2 中的 Swiftmailer - 无法发送电子邮件 [英] Swiftmailer in Yii2 - Unable to send email
问题描述
我正在使用基本的 Yii2 模板和 Swiftmailer 发送电子邮件..
I'm using basic Yii2 template and Swiftmailer to send email..
这是我的 config/web.php
代码:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport'=>'false',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'myemail@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
我的控制器代码是:
$fname = Yii::$app->request->post('fname');
$email = Yii::$app->request->post('email');
$industry = Yii::$app->request->post('industry');
$info = Yii::$app->request->post('info');
$mail = Yii::$app->mailer->compose()
->setFrom('myemail@gmail.com')
->setTo($email)
->setSubject('Test mail')
->setTextBody($info)
->send();
我收到了电子邮件日志,但没有发送电子邮件...
I'm getting email logs, but no email is being send...
谢谢.
推荐答案
为了让您的帐户不那么容易受到攻击,谷歌推出了这项政策.当我们在没有在 Google 上创建任何应用的情况下通过我们的帐户登录时,Google 会征求我们的许可,以确保我们帐户的安全.
In order to keep your account less vulnerable, google has introduced this policy. As we login through our account without creating any app on Google, Google ask for our permission to ensure the security of our account.
访问以下网址以解决此问题并选择开启"https://www.google.com/settings/security/lesssecureapps
Access below url to fix this problem and select "Turn on" https://www.google.com/settings/security/lesssecureapps
这篇关于Yii2 中的 Swiftmailer - 无法发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!