The problem is that in localhost I can send emails without any problem but when I try in my VPS (with hostinger) it is imposible to send an email. I always get the error:
" Connection timed out Cake\Network\Exception\SocketException"
My server has ubuntu 18.04.1 with php 7.3.2.
I have already allow the email port with ufw
I have seen the topic “Can send an email on Cakephp3” and anything works for me. The code that I have in my app.php is
I just configured postfix and I am able to send an email with the command echo “Test mail from postfix” | mail -s “Test Postfix” myemail@gmail.com at the terminal.
The problem now is that I do not know how to configure cakephp to send an email through postfix
I answer myself. With the default parameters it works perfectly
‘default’ => [
‘className’ => ‘Cake\Mailer\Transport\MailTransport’,
/*
* The following keys are used in SMTP transports:
*/
‘host’ => ‘localhost’,
‘port’ => 25,
‘timeout’ => 30,
‘username’ => null,
‘password’ => null,
‘client’ => null,
‘tls’ => null,
‘url’ => env(‘EMAIL_TRANSPORT_DEFAULT_URL’, null),
],
If anyone have doubts about how to configure postfix, I follow the next tutorial:
I have the following in app which is working for me without problems.
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
/*
* The following keys are used in SMTP transports:
*/
'host' => 'smtp.gmail.com',
'port' => 587,
'timeout' => 30,
'username' => 'youremail@domain.com',
'password' => 'XXXXXXXXXX',
'tls' => true
],
],
/**
* Email delivery profiles
*
* Delivery profiles allow you to predefine various properties about email
* messages from your application and give the settings a name. This saves
* duplication across your application and makes maintenance and development
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
* for more information.
*/
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'youremail@domain.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
Your email needs to be the one that is registered in gsuite. Also you may want to check your gmail settings that the smtp from authorised IP is allowed to send emails.