# CakePHP Mail SMTP Time Out

**URL:** <https://discourse.cakephp.org/t/cakephp-mail-smtp-time-out/10611>\
**Category:** Need Help\
**Created:** [September 6, 2022, 4:49pm UTC](https://discourse.cakephp.org/t/cakephp-mail-smtp-time-out/10611 "2022-09-06T16:49:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edu](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@Edu](https://discourse.cakephp.org/u/Edu)\
**Post date:** [September 6, 2022, 4:49pm UTC](https://discourse.cakephp.org/t/cakephp-mail-smtp-time-out/10611/1 "2022-09-06T16:49:39Z")

</div>

Hi, firstly sorry for my english, i’m brazilian and i’m learning english and cakephp.

I have an application with cakephp 3 and I’m trying to send email through it.

in app.php I configured like this:

```auto
 'EmailTransport' => [
    'default' => [
      'className' => 'Smtp',
      // The following keys are used in SMTP transports
      'host' => 'smtp.office365.com',
      'port' => 587,
      'timeout' => 30,
      'username' => 'login',
      'password' => 'senha',
      'client' => null,
      'tls' => true,
      'url' => env('smtp.office365.com', null),
    ],
  ],

```

in my controller

```auto

    public function contato()
    {
      if ($this->request->is('post')) {
        $data = $this->request->getData();

        $ip = getenv('REMOTE_ADDR');

          $email = new Email('default');
          $msg = "Nome: {$data['name']}<br>";
          $msg .= "E-mail: {$data['email']}<br>";
          $msg .= "Telefone: {$data['telefone']}<br>";
          $msg .= "Área de atuação: {$data['area']}<br>";
          $msg .= "Mensagem: <br>";
          $msg .= nl2br($data['message']);

          $email->from([$data['email']=>$data['name']])
          ->replyTo([$data['email']=>$data['name']])
          ->to('email@corporation.com.br')
          ->subject('[SITE]: ' . $data['name'])
          ->emailFormat('html')
          ->send($msg);

          $this->request->data = null;

          $this->Flash->success('Message Send.');
      }
    }

```

but it doesn’t work, it generates the following error in error.log

```auto

2022-09-06 13:33:42 Error: [Cake\Network\Exception\SocketException] SMTP timeout.

```

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 6, 2022, 10:24pm UTC](https://discourse.cakephp.org/t/cakephp-mail-smtp-time-out/10611/2 "2022-09-06T22:24:53Z")

</div>

First, if that’s your real password, you should change it right away, because everyone knows it now.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 6, 2022, 10:27pm UTC](https://discourse.cakephp.org/t/cakephp-mail-smtp-time-out/10611/3 "2022-09-06T22:27:34Z")

</div>

Second, does [this](https://github.com/cakephp/cakephp/issues/13403#issuecomment-509040260) answer your question? (This was the first hit when I googled cakephp office365.) You should be setting the from address to an address that your Office365 login has access to send as. Office365 will not accept messages that claim to be from somewhere else; that’s how spam happens.

---

<div class="post-metadata">

**Author:** ![yogeshsaroya](https://avatars.discourse-cdn.com/v4/letter/y/f05b48/32.png) [@yogeshsaroya](https://discourse.cakephp.org/u/yogeshsaroya)\
**Post date:** [September 7, 2022, 7:18am UTC](https://discourse.cakephp.org/t/cakephp-mail-smtp-time-out/10611/4 "2022-09-07T07:18:29Z")

</div>

What kind web hosting you are using ? Like if its godadday it won’t work, because godadday do not allow to use outbound SMTP.

if other then check SMTP rely status. sometime its hosting/server issue.
