Php 从本地主机发送但在托管后未发送的电子邮件?
我正在使用yii2mvc框架。我已经创建了一个电子邮件应用程序,它在localhost中运行良好,但在代码联机后会出现连接超时异常我使用ssl和tls用于encrytpion,我找不到任何真正的解决方案请帮助 我的配置文件代码是:Php 从本地主机发送但在托管后未发送的电子邮件?,php,smtp,yii2,Php,Smtp,Yii2,我正在使用yii2mvc框架。我已经创建了一个电子邮件应用程序,它在localhost中运行良好,但在代码联机后会出现连接超时异常我使用ssl和tls用于encrytpion,我找不到任何真正的解决方案请帮助 我的配置文件代码是: 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => false, 'transpor
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
]
Yii::$app->mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject('Hello')
->setTextBody('Hello')
->send();
Swift_TransportException
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
消息发送代码:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
]
Yii::$app->mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject('Hello')
->setTextBody('Hello')
->send();
Swift_TransportException
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
错误:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
]
Yii::$app->mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject('Hello')
->setTextBody('Hello')
->send();
Swift_TransportException
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
您应该尝试更换主机:
smtp.gmail.com
与
173.194.65.108
或gmail-smtp-msa.l.google.com
如果仍然无法工作,请尝试将端口更改为
25
或465
您应该尝试更换主机:
smtp.gmail.com
与
173.194.65.108
或gmail-smtp-msa.l.google.com
如果仍然无法工作,请尝试在配置文件中将端口更改为25
或465
:
- 将
更改为465,将端口
更改为ssl加密
- 在您的gmail帐户设置中,检查您是否启用了IMAP
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
]
Yii::$app->mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject('Hello')
->setTextBody('Hello')
->send();
Swift_TransportException
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
[1]
[2] 在配置文件中:
- 将
更改为465,将端口
更改为ssl加密
- 在您的gmail帐户设置中,检查您是否启用了IMAP
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
]
Yii::$app->mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject('Hello')
->setTextBody('Hello')
->send();
Swift_TransportException
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
[1]
[2] 从config.yml
spool:{type:memory}
然后,您将添加像这样的尝试捕捉
try{
$mailer = $this->getMailer();
$response = $this->getMailer()->send($message);
}catch(\Swift_TransportException $e){
$response = $e->getMessage() ;
}
否则
尝试以下端口号
'port' => 26
或
从config.yml
spool:{type:memory}
然后,您将添加像这样的尝试捕捉
try{
$mailer = $this->getMailer();
$response = $this->getMailer()->send($message);
}catch(\Swift_TransportException $e){
$response = $e->getMessage() ;
}
否则
尝试以下端口号
'port' => 26
或
也许这对你有帮助,这对你也有帮助。也许这对你有帮助,这对你也有帮助。我联系了我的服务提供商,希望它能帮助我。我联系了我的服务提供商,希望它能帮助我