Send email from CakePHP 3 remote SMTP server

I'm having trouble setting up my application to send Mails from my smtp server, which is on the same remote hosting as 1and1. I don’t know if something is missing:

  • I changed my app.php to the values ​​provided 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 of my hosting provider for connecting to their SMTP server.

smtp requiere comfig

I do not get any result. Does anyone have an idea what I can lose?

+4
source share
3 answers

It turned out to me that this is the name of the work class "Mail", and the rest are the default settings. Please do the following:

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

        ],
    ],
+1
source

Please do the 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,
    ],
],

tls 'tls' => true, .

0

className.

To use a gmail or office365 server, it should be like this:

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

All Articles