简体   繁体   English

Cakephp 3未知电子邮件错误

[英]Cakephp 3 Unknown Email error

I wanted to ask about sending emails in cakephp3. 我想问一下关于在Cakephp3中发送电子邮件的问题。

I am using cakephp3 docs, and configured everything as example shows. 我正在使用cakephp3文档,并按示例所示配置了所有内容。

But, when I try to send mail, this error appears: 但是,当我尝试发送邮件时,出现此错误:

Could not send email: unknown 无法发送电子邮件:未知

//app.php
'EmailTransport' => [

    'default' => [
        'className' => 'Mail',
        // The following keys are used in SMTP transports
        'host' => 'smtp.gmail.om',
        'port' => 465,
        'timeout' => 30,
        'username' => 'mymail@gmail.com',
        'password' => 'password',
        'client' => null,
        'tls' => null,
    ],
],

ContactController: 的ContactController:

public function contact() {

    if (isset($this->request->data) AND ($this->request->is('post'))) {
        $email = new Email('default');
        if ($email->from(['mymail@gmail.com' => 'My Site'])->to('othermail@gmail.com')->subject('Hello')->send('Message')) {
            //pr( 'ok');
        }
    }
}

Is this a generic error message (, which may have many reasons, in my opinion)? 这是否是一般性错误消息(我认为可能有很多原因)? it has no value in context of debug. 它在调试的上下文中没有任何价值。

You want to use an SMTP server, but you've configured to use the Mail transport! 您要使用SMTP服务器,但已配置为使用Mail传输!

The className option should be set to Smtp . className选项应设置为Smtp The host should probably also be different ( ssl:// prefixed), or you should enable TLS, please be sure that you read through the questions/answers found with the search linked below. 主机可能也应该不同(以ssl://为前缀),或者您应该启用TLS,请确保您通读了通过以下搜索链接找到的问题/答案。

See also 也可以看看

The host name in default configuration is incorrect. 默认配置中的主机名不正确。

it should be 它应该是

'host' => 'smtp.gmail.com',

instead of 代替

'host' => 'smtp.gmail.om',
use Cake\Mailer\Email;

Email::configTransport('gmail', [
    'host' => 'smtp.gmail.com',
    'port' => 587,
    'username' => 'my@gmail.com',
    'password' => 'secret',
    'className' => 'Smtp',
    'tls' => true
]);

Yous this code : Replace My@gmail.com and Secret with you credentials offcourse and after that use you code it will work. 您的代码:将My@gmail.com和Secret替换为您的凭据脱机,然后使用您的代码即可使用。

One thing that's always forgotten is the Email profiles 永远被遗忘的一件事是电子邮件配置文件

   `'Email' => [
    'default' => [
        'transport' => 'gmail', //this allows the email class to use the gmail settings
        'from' => 'youremail@gmail.com',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    ],
    ],`

And by the way you can set up multiple profiles for the like testing, development etc 顺便说一下,您可以为测试,开发等设置多个配置文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM