我正在尝试使用Laravel
在Swift Mailer
发送电子邮件,我一直在尝试从过去3天,但No Luck
。
我有Godaddy共享主机,我已经与Customer Support
讨论过,他们说从那边没有问题
我无法找到此代码中的错误。
已经提到这篇文章,但没有得到任何解决方案。
码
$transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('[email protected]')
->setPassword('*****');
$nam = 'abc';
$from = '[email protected]';
$message = \Swift_Message::newInstance($subject)
->setFrom(array($from => $name))
->setTo(array($to))
->setBody($body);
$message->setContentType("text/html");
$mailer = \Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
return $result;
Please ignore Variable declaration, like $subject and ect....
Port Tried。
1. 465
2. 587
3. 80
4. 25
5. 110 ( Gmail Commercial Email )
它显示错误
消息:fsockopen():无法连接到ssl://smtp.gmail.com:465(连接被拒绝)
我使用了godaddy的旧服务器,我可以发送电子邮件。我不得不改变sendmail的路径。你可以在info.php上看到它 - >
// Show all information, defaults to INFO_ALL
phpinfo();
并搜索:“sendmail_path”......
就我而言,sendmail_path是“/ usr / sbin / sendmail -t -i”
你应该把它放在config / mail.php上:
/*
|-----------------------------------------------------------------
| Sendmail System Path
|-----------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail -t -i',
我有一个解决方案。使用此配置:
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'htmlLayout' => '@frontend/views/user/mail/layouts/html',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp-relay.gmail.com', // e.g. smtp.mandrillapp.com or smtp.gmail.com
'username' => '',
'password' => '',
'port' => '465',
'encryption' => 'ssl',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
],
],
检查您的smtp连接电子邮件,尝试使用谷歌电子邮件进行测试
smtp.gmail.com port:587 secureconnection:true
在谷歌电子邮件安全连接中禁用
这个配置对我有用!
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
更改配置后,请确保清除缓存。
php artisan cache:clear