Problème d'envoi de mail avec Cakephp 3

Par Olivier Dupuy, il y a 11 ans


Bonjour,

Voici ma configuration email:

'EmailTransport' => [ 'default' => [ 'className' => 'Mail', // The following keys are used in SMTP transports 'host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 30, 'username' => 'odupuy66@gmail.com', 'password' => 'xxxxxxxxxxxxx', 'client' => null, 'tls' => true, ], 'gmail' => [ 'className' => 'Mail', 'host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 30, 'username' => 'odupuy66@gmail.com', 'password' => 'xxxxxxxxxxxxxx', 'client' => null, 'tls' => true ], 'kreatik' => [ 'className' => 'Mail', // The following keys are used in SMTP transports 'host' => 'smtp.kreatik-studio.com', 'port' => 587, 'timeout' => 30, 'username' => 'contact@kreatik-studio.com', 'password' => 'xxxxxxxxxxxx', 'client' => null, 'tls' => null ], ], 'Email' => [ 'default' => [ 'transport' => 'kreatik', 'from' => 'contact@kreatik-studio.com', 'charset' => 'utf-8', 'headerCharset' => 'utf-8', ], 'gmail' => [ 'transport' => 'gmail', 'from' => 'odupuy66@gmail.com', 'charset' => 'utf-8', 'headerCharset' => 'utf-8', ], ],

La méthode utilisée est :

$email = new Email('default'); $email->template('welcome_1') ->emailFormat('html') ->to('olivier.dupuy74@htomail.fr') ->from('contact@kreatik-stduio.com') ->send();

Le problème c'est qu'aucun mail part, même en local quand j'utilise gmail, il me fait une erreur 500:

Could not send email: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

Je ne comprends pas pourquoi.

J'ai débugue mon objet $email et apparemment il a l'air de prendre la configuration en compte.

Pouvez vous m'aider???

1 réponse

Grafikart, il y a 11 ans

Lit la doc et les commentaire du code. Si tu laisse className à "Mail" il n'utilisera pas les informations SMTP mais la fonction mail.