Hi
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' => 'mail.abc.com',
'port' => 465,
'username' => 'support@abc.com,
'password' => 'password',
'tls' => true // Tired with true and false
]);
$mailer = new Mailer('default');
$mailer->setTransport('Manual');
try {
$res = $mailer->setFrom(['support@abc.com' => 'My Site'])
->setTo('xyz@gmail.com')
->setSubject('About')
->deliver('My message');
pr($res);
} catch (\Throwable $th) {
ec($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.
Thanks