CakePhp 4 中 SMTP 的邮件程序问题
我正在使用 CakePHP 4.2.8 并尝试通过 smtp 发送电子邮件,但出现超时错误,并在其他 php 应用程序中使用相同的电子邮件帐户(使用 phpmailer )并且工作正常。 这是我的代码。
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' => '[email protected]',
'password' => 'password',
'tls' => true // Tired with true and false
]);
$mailer = new Mailer('default');
$mailer->setTransport('Manual');
try {
$res = $mailer->setFrom(['[email protected]' => 'My Site'])
->setTo('[email protected]')
->setSubject('About')
->deliver('My message');
pr($res);
} catch (\Throwable $th) {
ec($th);
}
}
收到此错误
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
请帮助我我的代码有什么问题。使用相同的端口和其他信息与核心 php Web 应用程序中的 phpmailer 一起工作。
谢谢
更新
我找到了解决方案,端口应该是587。
I am using CakePHP 4.2.8 and trying to send email via 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' => '[email protected]',
'password' => 'password',
'tls' => true // Tired with true and false
]);
$mailer = new Mailer('default');
$mailer->setTransport('Manual');
try {
$res = $mailer->setFrom(['[email protected]' => 'My Site'])
->setTo('[email protected]')
->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
UPDATE
I found solutions, port should be 587.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论