简体   繁体   中英

Send Email from SMTP remote server CakePHP 3

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:

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

     '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 requiere comfig

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

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

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

        ],
    ],

In my case only was problem in className.

For using gmail or office365 server it should be so:

'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),
        ],
    ],

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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