Cant send an email on cakephp3


#1

I can’t get cakephp3 to send emails. In cakephp2 I could do this no problem. I am using the latest WAMP, and cakephp3.3 on Windows 7. I tried to follow the directions but it looks like I am getting something basic wrong. Do I also need to configure Wamp as I checked the php.ini-development file but there is no smtp entry to change

error- stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed stream_socket_client(): Failed to enable crypto stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)

I also set up wamp for email and I still get the same error.

controller

public function singleTutorEmail(){

   $email = new Email();
   $email->transport('gmail3');

   $to='jjxxx@gmail.com';
   $subject='testing';
   $message='hello, dfsfsdfsdf sdfsdf';

   $email->from(['jjxxx@gmail.com' => 'test'])
              ->to($to)
              ->subject( $subject)                   
              ->send($message);

}

in app.php

‘EmailTransport’ => [
‘default’ => [
‘className’ => ‘Mail’,
// The following keys are used in SMTP transports
’host’ => ‘localhost’,
‘port’ => 465,
‘timeout’ => 30,
‘username’ => ‘user’,
‘password’ => ‘secret’,
‘client’ => null,
‘tls’ => null,
‘url’ => env(‘EMAIL_TRANSPORT_DEFAULT_URL’, null),
],
‘gmail3’ => [
‘className’ => ‘Smtp’,
‘host’ => ‘ssl://smtp.gmail.com’,
‘port’ => 465,
‘timeout’ => 30,
‘username’ => ‘jjxxx@gmail.com’,
‘password’ => ‘xxx’,
‘client’ => null,

    ],
],

#2

Make sure you have TLS enabled, it will prepend ssl:// to the host automatically:

'gmail3' => [
    'className' => 'Smtp',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'timeout' => 30,
    'username' => 'jjxxx@gmail.com',
    'password' => 'xxx',
    'client' => null,
    'tls' => true
]

#3

This didnt work as I got

stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed stream_socket_client(): Failed to enable crypto stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)


#4

I have exactly the same problem.

On my developement-machine (vagrant with ubuntu/trusty32, nginx, php7, CakePHP 3.3.0) I am having no problems to connect the smtp-server an send mails.

On the production-server (a cloud-based service, php7) I get the described error.
I found this post describing a similar behaviour. But my SSL-skills are not very good. Maybe this helps to investigate the cause of the error.


#5

Hi, The post seems be the the solution but I dont know how to implement a solution from that website in my windows wamp64 so I am kind of stuck


#7

Also check this:

  • OpenSSL should be configured on your production server
  • If you want to use Gmail as email relay, you will need to have access for less secure apps enabled in your Google account for this to work: support article.

Source: http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports


#8

I have openssl on my wamp loaded.

I cant get anywhere with emails in cakephp3 and I need them. Any help please


#9

It works if I add in these lines as I have php >5.6 . This is not in the docs of cakephp3

‘gmail3’ => [
‘className’ => ‘Smtp’,
‘host’ => ‘ssl://smtp.gmail.com’,
‘port’ => 465,
‘timeout’ => 30,
‘username’ => ‘jjxxx@gmail.com’,
‘password’ => ‘xxx’,
‘client’ => null,
‘context’ => [
‘ssl’ => [
‘verify_peer’ => false,
‘verify_peer_name’ => false,
‘allow_self_signed’ => true
]
]


#10

This works but the code isnt in the docs, Is there a problem with the docs on this point?


#11

It Worked for me, tnx.


#12

Any other solution?
I still having this issue…

Only in my webserver, that’s works fine on localhost;
When I publish, I can’t send emails anymore.

if I use gmail, the error change to
Network is unreachable Cake\Network\Exception\SocketException

I try change email sender, and now the error is

CakePHP show me this error…
//php_network_getaddresses: getaddrinfo failed: Name or service not known


#13

Recommend the Test Mail Server Tool for dev setups on Windows:
https://toolheap.com/test-mail-server-tool/

Your email pops up as text files.

in app.php

        'className' => 'Smtp',
            // The following keys are used in SMTP transports
            'host' => 'localhost',
            'port' => 25,

#14

I am using cakephp3.
In localhost with xamp I can send email using gmail, but in prodution mode on DigitalOcean I can’t. TimeOut error I get.

Someone can help me?

Thanks


#15

Firewall issues? Are you allowed out on that port on your digital ocean server?

This may be useful:


#16

Thanks hakim,

My firewall is disabled and this link is not usefull. I need send email with gmal smtp.
I have another droplet with same code and it runs, however this don’t.

:frowning:


#17

Did you solve it? Are both droplets the exact same?

Also try a single test php file, sending vanilla php mail on the droplet.


#18

Digital Ocean blocks smtp for two months


#19

Ok, that might depend on payment plan?. I got a droplet recently. I assumed outgoing mail would be blocked, but after setup, I got Postfix (sendmail alternative) is working.


#20

This did not work for me and I am having this issue and I don’t knwo how to fix it… I am not running a gmail transport I want this to use a hosted SMTP account and it works fine in Local, but once up in the server the transport fails to connect to the email account… Here is my transport…

‘myTransport’=>[
‘host’ => ‘ssl://box.mydomain.com’,
‘port’ => 465,
‘username’ => ‘username@mydomain.com’,
‘password’ => ‘*****’,
‘className’ => ‘Smtp’,
‘timeout’ => 30,
‘client’ => null,
‘context’ => [
‘ssl’ => [
‘verify_peer’ => false,
‘verify_peer_name’ => false,
‘allow_self_signed’ => true
]
],
‘tls’ => false,
‘smtpd_tls_auth_only’ => ‘true’,
‘log’=> true,
‘url’ => env(‘EMAIL_TRANSPORT_DEFAULT_URL’, null),
]

I’ve tried the ‘tls’ as true and it does not work, I’ve tried creating another account and nothing. Please some help here, I am very desperate at this point. I am running CakePhP 3.4 in a php 5.6

Any help will be much appreciated.

Thanks guys ;(