1

I am using cakephp 3.0. I am trying to send mail using cakephp through gmail SMTP Server. I am trying to do it from my localhost so I don't have ssl. This is the configuration I've done in app.php:

'EmailTransport' => [
    'gmail'=>[
        'className'=>'Smtp',
        'host'=>'smtp.gmail.com',
        'port'=>587,
        'timeout' => 60,
        'username'=>'myemail@gmail.com',
        'password'=>'mypassword',
        'tls' => true,
    ]
]

This is where I've created my email profile :

'Email' => [
    'gmail' => [
        'transport' => 'gmail',
        'from' => 'myemail@gmail.com'
    ]
],

This is the code from my custom mailer class :

    $mail
        ->to($email)
        ->profile('gmail')
        ->subject($this->subject)
        ->emailFormat('html')
        ->template('welcome')
        ->viewVars([
            $name=>$name,
            $code=>$code
        ]);

I've already allowed access to less secure apps in my gmail account. This is the error cakephp is throwing :

SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS

Attaching a complete snapshot of the error :

enter image description here

chris85
  • 23,846
  • 7
  • 34
  • 51
Sourabh
  • 1,757
  • 6
  • 21
  • 43

1 Answers1

4

Found the solution. Added these parameters in the transport config to bypass ssl authentication:

        'context' => [
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            ]
        ]

Worked like a charm.

Sourabh
  • 1,757
  • 6
  • 21
  • 43