Mailer issue with SMTP


I am using CakePHP 4.2.8 and trying to send email vai smtp. but i am getting time out error and used same email account in other php app (using phpmailer ) and its working fine.
Here is my code.

use Cake\Mailer\Mailer;
use Cake\Mailer\TransportFactory;

public function sendEmail()

    TransportFactory::setConfig('Manual', [
        'className' => 'Smtp',
        //'className' => 'Debug',
        'host' => '',
        'port' => 465,
        'username' => ',
        'password' => 'password',
        'tls' => true // Tired with true and false

    $mailer = new Mailer('default');

    try {
        $res = $mailer->setFrom(['' => 'My Site'])
        ->deliver('My message');
    } catch (\Throwable $th) {

Getting this error

Cake\Network\Exception\SocketException Object
[_attributes:protected] => Array

[_messageTemplate:protected] => 
[_responseHeaders:protected] => 
[_defaultCode:protected] => 0
[message:protected] => SMTP timeout.
[string:Exception:private] => 
[code:protected] => 0
[file:protected] => /Applications/MAMP/htdocs/cake/superpad/vendor/cakephp/cakephp/src/Mailer/Transport/SmtpTransport.php
[line:protected] => 510

Please help me what is wrong with my code. Using same port and other info its working with phpmailer in core php web app.


have you tried port 587 instead of Port 465?

I know it seems weird because it works with another PHP app using phpmailer but I have seen mailservers not handling TLS (not SSL because it is deprecated) correctly on port 465. But some mailservers still allow SSL connections via 465.

Otherwise if that also doesn’t work and you don’t care about 'tls' => true have you tried setting the port to 25 since it is the default SMTP port for non encrypted mails?

There is nothing really wrong with your cakephp code.

1 Like

Thanks , it’s working with 587.

at cPanel > email it was showing 465 for IMPS.

IMAPS definitely shouldn’t be accessible via 465.
IMAP is 110 and IMAPS is 995 so if your cPanel shows you 465 for IMAPS then its totally borked in some way.

Besides the fact that IMAP can’t even be used to send mails, its only used to receive emails.