CakePHP Mail SMTP Time Out

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:

 '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


    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


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

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

3 Likes

Second, does this 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.

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.