Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从本地主机发送但在托管后未发送的电子邮件?_Php_Smtp_Yii2 - Fatal编程技术网

Php 从本地主机发送但在托管后未发送的电子邮件?

Php 从本地主机发送但在托管后未发送的电子邮件?,php,smtp,yii2,Php,Smtp,Yii2,我正在使用yii2mvc框架。我已经创建了一个电子邮件应用程序,它在localhost中运行良好,但在代码联机后会出现连接超时异常我使用ssl和tls用于encrytpion,我找不到任何真正的解决方案请帮助 我的配置文件代码是: 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => false, 'transpor

我正在使用yii2mvc框架。我已经创建了一个电子邮件应用程序,它在localhost中运行良好,但在代码联机后会出现连接超时异常我使用ssl和tls用于encrytpion,我找不到任何真正的解决方案请帮助

我的配置文件代码是:

'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
有关gmail设置的信息:

'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
有关gmail设置的信息:

'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 


也许这对你有帮助,这对你也有帮助。也许这对你有帮助,这对你也有帮助。我联系了我的服务提供商,希望它能帮助我。我联系了我的服务提供商,希望它能帮助我