我有以下smtp配置,但我不确定,因为有时我会在发送电子邮件时遇到ssl超时。
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
'useFileTransport' => true,
],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@backend/mail',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'in-v3.mailjet.com',
'username' => 'a3027c3xxx',
'password' => 'c838779xxx',
'port' => '465',
'encryption' => 'ssl',
],
],
然后我像这样使用
$message = Yii::$app->mail->compose();
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo("mymail@gmail.com")
->setSubject('Password Reset')
->setHtmlBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->send();
结果有时候我会面临超时。
但是,如果我直接从swiftmailler类发送,如下面的代码,它成功发送100封电子邮件,没有任何ssl超时
$transport = \Swift_SmtpTransport::newInstance('in-v3.mailjet.com', 465)
->setUsername('myusername')
->setPassword('s3cr3t')
->setEncryption('ssl');
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance('Password Reset')
->setFrom(array('no-reply@myweb.com' => 'My Web'))
->setTo(array('some@one.com'))
->setBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->setContentType("text/html")
;
$result = $mailer->send($message);
如果你问我的ssl如何在这里超时是我的问题链接
How to solve Swift_TransportException Connection to ssl Timed Out error?
所以我开始想是因为我的配置,这个ssl超时了吗?或者不同的发送方式?从第一个例子和第二个例子?
<{1>}common\config\main-local.php
中有一个mailer => []
,mail => []
是否有必要?
你能解释一下useFileTransport
究竟是什么吗?
提前致谢。
PS。我已经使用了任何第三方和端口配置,但仍面临ssl超时问题。