从SMTP远程服务器CakePHP 3发送电子邮件

时间:2021-02-25 18:16:24

I'm facing some problems configuring my app to send Mails from my smtp server, which is located in one remote hosting with 1and1. I don't know if I'm missing something:

我在配置我的应用程序以从我的smtp服务器发送邮件时遇到一些问题,该服务器位于一个带有1and1的远程主机中。我不知道我是否遗漏了一些东西:

  • I've changed my app.php to the values given by my hosting provider:

    我已将app.php更改为托管服务提供商提供的值:

    'EmailTransport' => [
        'default' => [
            'className' => 'Mail',
            'host' => 'smtp.1and1.com',
            'port' =>'587' ,
            'timeout' => 30,
            'username' => 'me@dns.com',
            'password' => '******',
            'client' => null,
            'tls' => null,
        ],
    ],
    
    'Email' => [
        'default' => [
            'transport' => 'default',
            'from' => '@localhost',
            //'charset' => 'utf-8',
            //'headerCharset' => 'utf-8',
        ],
    ], 
    

Here you can see the instructions given by my hosting provider to connect to their smtp server.

在这里,您可以看到我的托管服务提供商提供的连接到他们的smtp服务器的说明。

从SMTP远程服务器CakePHP 3发送电子邮件

I don't get any result. Does anybody have an Idea what may I be missing?

我没有得到任何结果。有没有人有一个想法,我可能会缺少什么?

3 个解决方案

#1


1  

I got it working setting classname as 'Mail' and the rest of the parameters as default. Please, do as follows:

我得到它的工作设置classname为'Mail',其余的参数默认。请按以下方式行事:

'EmailTransport' => [
        'default' => [
            'className' => 'Mail',
            // The following keys are used in SMTP transports
            'host' => 'localhost',
            'port' => 25,
            'timeout' => 30,
            'username' => 'user',
            'password' => 'secret',
            'client' => null,

        ],
    ],

#2


0  

Please do as following:

请执行以下操作:

//Adding Smtp information for sending mail through smtp instead of php mail function on local server / live server

'EmailTransport' => [
    'default' => [
        'className' => 'Smtp',
        'host' => 'smtp.1and1.com',
        'port' =>'587' ,
        'timeout' => 30,
        'username' => 'me@dns.com',
        'password' => '******',
        'client' => null,
        'tls' => null,
    ],
],

You can also enable tls to 'tls' => true if required.

如果需要,您还可以启用tls到'tls'=> true。

#3


0  

In my case only was problem in className.

在我的情况下,只有className中的问题。

For using gmail or office365 server it should be so:

对于使用gmail或office365服务器,它应该是这样的:

'EmailTransport' => [
        'default' => [
            'className' => 'Mail',
            // The following keys are used in SMTP transports
            'host' => 'smtp.office365.com',
            'port' => 587,
            'timeout' => 30,
            'username' => 'my@email.com',
            'password' => 'myPassword',
            'client' => null,
            'tls' => true,
            'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
        ],
    ],

#1


1  

I got it working setting classname as 'Mail' and the rest of the parameters as default. Please, do as follows:

我得到它的工作设置classname为'Mail',其余的参数默认。请按以下方式行事:

'EmailTransport' => [
        'default' => [
            'className' => 'Mail',
            // The following keys are used in SMTP transports
            'host' => 'localhost',
            'port' => 25,
            'timeout' => 30,
            'username' => 'user',
            'password' => 'secret',
            'client' => null,

        ],
    ],

#2


0  

Please do as following:

请执行以下操作:

//Adding Smtp information for sending mail through smtp instead of php mail function on local server / live server

'EmailTransport' => [
    'default' => [
        'className' => 'Smtp',
        'host' => 'smtp.1and1.com',
        'port' =>'587' ,
        'timeout' => 30,
        'username' => 'me@dns.com',
        'password' => '******',
        'client' => null,
        'tls' => null,
    ],
],

You can also enable tls to 'tls' => true if required.

如果需要,您还可以启用tls到'tls'=> true。

#3


0  

In my case only was problem in className.

在我的情况下,只有className中的问题。

For using gmail or office365 server it should be so:

对于使用gmail或office365服务器,它应该是这样的:

'EmailTransport' => [
        'default' => [
            'className' => 'Mail',
            // The following keys are used in SMTP transports
            'host' => 'smtp.office365.com',
            'port' => 587,
            'timeout' => 30,
            'username' => 'my@email.com',
            'password' => 'myPassword',
            'client' => null,
            'tls' => true,
            'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
        ],
    ],