使用Yii發送電子郵件時出現問題,問題有時會導致ssl超時,但是有時候郵件發送會很順利。如何解決Swift_TransportException連接到ssl超時錯誤?
錯誤說這樣的事情
Swift_TransportException
Connection to ssl://in-v3.mailjet.com:465 Timed Out
以下是錯誤圖像
讀了一些文章後,它看起來就像是因爲插座是超時,所以應該重新開始插座。
這是我閱讀的文章。
swiftmailer and Yii2 not working 1 out of 10 time
How to close Smtp connection in SwiftMailer
這是我在common\config\main-local.php
配置
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@backend/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'in-v3.mailjet.com',
'username' => 'myUserName',
'password' => 'myS3cr3tP4ss',
'port' => '465',
'encryption' => 'ssl',
],
],
下面是我在我的控制器
$message = Yii::$app->mail->compose();
if (Yii::$app->user->isGuest) {
$message->setFrom('[email protected]');
} else {
$message->setFrom(Yii::$app->user->identity->email);
}
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo($model->email)
->setSubject('Reset Password')
->setHtmlBody($this->renderAjax('//email/_content',['content' => 'email content goes here']))
->send();
return $this->render('confirmation_sent');
發送電子郵件,我如何才能停止和啓動連接用我的上面的代碼?
我已經把這段代碼正是之前$message
if (Yii::$app->mailer->getTransport()->isStarted()) {
Yii::$app->mailer->getTransport()->stop();
}
Yii::$app->mailer->getTransport()->start();
但它仍然顯示SSL time out
有時。
我問這個問題mailjet,並得到這個響應
Hi, Thank you for your reply.
Ok, please try with port 443 with SSL or: 25,80, 2525 with no encryption, 587 and 588 with TLS.
Let me know if it works.
已經嘗試給出加密所有的端口,但它仍然是相同的,有時我滿足Timed Out
修訂
使用try catch有時給我Failed to authenticate on SMTP server with username "a3027c30a1c1f6f60d2f9d7813360b46" using 3 possible authenticators1
。
使用try catch也給我Connection to ssl://in-v3.mailjet.com:465 Timed Out
,它顯示某個時間。
這是從我們的服務器我traceroute命令mailjet
traceroute to in-v3.mailjet.com (37.59.74.234), 30 hops max, 60 byte packets
1 gateway (123.231.250.129) 1.084 ms 1.114 ms 3.485 ms
2 36.37.76.84 (36.37.76.84) 17.495 ms 17.497 ms 36.37.76.70 (36.37.76.70) 1 7.215 ms
3 36.37.77.68 (36.37.77.68) 30.878 ms 36.37.77.14 (36.37.77.14) 30.322 ms 3 2.661 ms
4 36.37.77.39 (36.37.77.39) 33.103 ms * *
5 * * *
6 * * *
7 * * gblx.as3549.ny.us (213.251.130.102) 362.627 ms
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
這是因爲不同的Yii::$app->mailer
啓動,停止插座,Yii::$app->mail
發送電子郵件?
我對這些錯誤,因爲SSL套接字停止?請解釋一下這個錯誤是怎麼出現的。
在此先感謝。
如果這是因爲端口,那麼爲什麼有時我可以成功發送電子郵件? –
也許它適用於兩種協議,其中一種協議不穩定。 – gud3
我要求mailjet,他回覆了 嗨, 謝謝你的回覆。 好的,請使用SSL端口443或: 25,80,2525不加密,587和588加TLS。 讓我知道它是否有效。 最好, 我已經嘗試了所有的端口,但它仍然是一樣的。有時候會讓我超時。 –