# Cant send an email on cakephp3

**URL:** <https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043>\
**Category:** Uncategorized\
**Created:** [August 24, 2016, 1:08pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043 "2016-08-24T13:08:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [August 24, 2016, 1:08pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/1 "2016-08-24T13:08:09Z")

</div>

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,

```
    ],
],
```

---

<div class="post-metadata">

**Author:** ![joris](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/joris/32/338_2.png) [@joris](https://discourse.cakephp.org/u/joris)\
**Post date:** [August 25, 2016, 6:46am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/2 "2016-08-25T06:46:51Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [August 25, 2016, 12:22pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/3 "2016-08-25T12:22:12Z")

</div>

> [@joris](#):
>
> ‘client’ =\> null,  
> ‘tls’ =\> true

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)

---

<div class="post-metadata">

**Author:** ![Tobse](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tobse/32/236_2.png) [@Tobse](https://discourse.cakephp.org/u/Tobse)\
**Post date:** [August 26, 2016, 12:46pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/4 "2016-08-26T12:46:02Z")

</div>

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](http://marius.me.uk/blog/2016/03/openssl-sclient-vs-php-stream-socket-client/) post describing a similar behaviour. But my SSL-skills are not very good. Maybe this helps to investigate the cause of the error.

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [August 27, 2016, 7:02am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/5 "2016-08-27T07:02:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joris](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/joris/32/338_2.png) [@joris](https://discourse.cakephp.org/u/joris)\
**Post date:** [September 15, 2016, 1:40pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/7 "2016-09-15T13:40:51Z")

</div>

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](https://support.google.com/accounts/answer/6010255).

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

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [September 22, 2016, 7:48am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/8 "2016-09-22T07:48:09Z")

</div>

I have openssl on my wamp loaded.

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

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [September 22, 2016, 9:19am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/9 "2016-09-22T09:19:34Z")

</div>

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  
]  
]

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [September 23, 2016, 5:19am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/10 "2016-09-23T05:19:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JoseLuis.Reyes](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@JoseLuis.Reyes](https://discourse.cakephp.org/u/JoseLuis.Reyes)\
**Post date:** [May 15, 2017, 3:01pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/11 "2017-05-15T15:01:19Z")

</div>

It Worked for me, tnx.

---

<div class="post-metadata">

**Author:** ![johnnyboy](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@johnnyboy](https://discourse.cakephp.org/u/johnnyboy)\
**Post date:** [April 8, 2018, 12:23am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/12 "2018-04-08T00:23:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.cakephp.org/u/hakim)\
**Post date:** [April 9, 2018, 10:34am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/13 "2018-04-09T10:34:12Z")

</div>

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

Your email pops up as text files.

in app.php

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

```

---

<div class="post-metadata">

**Author:** ![alexmartins](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@alexmartins](https://discourse.cakephp.org/u/alexmartins)\
**Post date:** [April 9, 2018, 5:59pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/14 "2018-04-09T17:59:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.cakephp.org/u/hakim)\
**Post date:** [April 11, 2018, 11:49am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/15 "2018-04-11T11:49:51Z")

</div>

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

This may be useful:

> **[SMTP timeout | DigitalOcean](https://www.digitalocean.com/community/questions/smtp-timeout)**
>
> Followed the instructions here: https://www.digitalocean.com/community/articles/how-to-install-iredmail-on-ubuntu-12-04-x64 I can receive e-mail but when I try sending e-mail to any address (tried gmail, icloud, etc) the logs show something like...

---

<div class="post-metadata">

**Author:** ![alexmartins](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@alexmartins](https://discourse.cakephp.org/u/alexmartins)\
**Post date:** [April 11, 2018, 12:36pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/16 "2018-04-11T12:36:32Z")

</div>

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.

☹

---

<div class="post-metadata">

**Author:** ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.cakephp.org/u/hakim)\
**Post date:** [May 21, 2018, 4:41pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/17 "2018-05-21T16:41:29Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![alexmartins](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@alexmartins](https://discourse.cakephp.org/u/alexmartins)\
**Post date:** [May 21, 2018, 5:27pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/18 "2018-05-21T17:27:37Z")

</div>

Digital Ocean blocks smtp for two months

---

<div class="post-metadata">

**Author:** ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.cakephp.org/u/hakim)\
**Post date:** [May 22, 2018, 9:19am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/19 "2018-05-22T09:19:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![elhotrod](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@elhotrod](https://discourse.cakephp.org/u/elhotrod)\
**Post date:** [June 8, 2018, 5:08am UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/20 "2018-06-08T05:08:24Z")

</div>

> [@jagguy](#):
>
> ‘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  
> ]  
> ]

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 ;(

---

<div class="post-metadata">

**Author:** ![Ruslan](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@Ruslan](https://discourse.cakephp.org/u/Ruslan)\
**Post date:** [August 7, 2018, 1:15pm UTC](https://discourse.cakephp.org/t/cant-send-an-email-on-cakephp3/1043/21 "2018-08-07T13:15:32Z")

</div>

Here is my config, and it works:

```
    public $mail7 = array(
    'host' => 'mail7.server.com',
    'from' => array('info@server.com' => 'Server'),
    'port' => 25,
    'username' => 'user',
    'password' => 'pass',
    'transport' => 'Smtp',
    'tls' => true,
    'context' => ['ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    ]],
    'log' => true,
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
);

```

I use php 5.6, CakePHP 2.6.
