【发布时间】:2017-03-30 08:49:29
【问题描述】:
我有以下 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 是否因为我的配置而超时?还是不同的发送方式?从第一个例子和第二个例子?
在common\config\main-local.php 中有一个mailer => [] 和mail => [] 是必需的吗?
你能解释一下useFileTransport到底是什么吗?
提前致谢。
附言。我已经使用了任何第三方和端口配置,但仍然面临 ssl 超时问题。
【问题讨论】:
-
你有什么解决办法吗?我和你有同样的问题。直接从 swift mailer 使用它可以工作。但不发送消息默认值。
标签: yii2