扩展 YiiMaill (Swiftmailer) 无法从 gmail 发送 SMTP

Extension YiiMaill (Swiftmailer) can't send SMTP from gmail

我有一个 PHP 应用程序,它是 运行 Yii Framework,它使用 YiiMail 扩展基于 Swiftmailer.

我的应用程序昨天运行良好,但今天启动时出现以下错误:

fsockopen(): SSL 操作失败,代码为 1。OpenSSL 错误消息: error:14090086:SSL routines:ssl3_get_server_certificate:certificate 验证失败

我的 Yii 应用配置:

'mail' => 
  array('class' => 'application.extensions.yii-mail.YiiMail',
        'transportType' => 'smtp', 
        'transportOptions' => array(
             'host' => 'smtp.gmail.com', 
             'username' => '**@gmail.com', 
             'password' => '***', 
             'port' => '465', 
             'encryption'=>'tls' ), 
         'viewPath' => 'application.views.mail', 
         'logging' =>false, 
         'dryRun' => false
 )

答案:快速解决方案

我的应用程序在Windows中是运行,所以我现在做了一个快速配置来解决这个问题。

我用 sendmail 进行了配置,它在我的 php.ini 文件中启用。

Ps:主要问题是如果您在同一个 php 中有很多应用程序 运行。这个问题对我来说怎么没有,它是独立的应用程序,我刚刚做了。

像这样:

sendmail.ini

[sendmail]
smtp_server=smtp.gmail.com
smtp_port = 587
#default_domain = gmail.com it's is not necessary
auth_username= your gmail@gmail.com
auth_password=your password

php.ini

[mail function]
sendmail_path = "path to sendmail installation"
SMTP = smtp.gmail.com
smtp_port = 587

这是我在 Yii2 项目中的工作 smtp 设置: common/config/main-local.php

return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=bd-sys',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.gmail.com',
                'username' => '******@gmail.com',
                'password' => '******',
                'port' => 587,
                'encryption' => 'tls',
            ],
        ],
    ],
];

如果您当前的配置以前工作正常,然后突然停止。考虑查看以下内容:

我之前遇到过类似的问题,启用 Less Secure Apps,然后当我为我的 google 帐户设置 2 Step Verification 时,它停止工作了。

然后生成APP密码,大功告成!