首页 > 解决方案 > 我正在使用 CakePHP 3.7 开发一个网站。我在 localhost 上工作,想从 localhost 向 gmail 发送电子邮件,但出现错误

问题描述

我能够从 xampp (Mecury) localhost 向 localhost 发送电子邮件。但是当我尝试从 Gmail 向本地主机发送电子邮件时,我无法做到这一点。

我们的主要目的是从 Gmail 帐户向本地主机发送电子邮件。我该怎么做,任何帮助都将不胜感激。

这是我的app.php文件中的代码:

'EmailTransport' => [
        'default' => [
            //'className' => MailTransport::class,
            'className' => 'Smtp',
            /*
             * The following keys are used in SMTP transports:
             */
            'host' => 'smtp.gmail.com',
            'port' => 587,
            'timeout' => 30,
            'username' => 'my@gmail.com',
            'password' => 'secret',
            'client' => null,
            'tls' => null,
            'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
        ],
    ],

    
'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => ['demotest@localhost.com' => 'demotest'],
        //'charset' => 'utf-8',
         //'headerCharset' => 'utf-8',
    ],
],

标签: cakephpcakephp-3.xcakephp-3.7

解决方案


推荐阅读