gpt4 book ai didi

php - 无法连接到 SMTP 服务器。在 CakePHP 中

转载 作者:太空宇宙 更新时间:2023-11-03 15:01:57 25 4
gpt4 key购买 nike

我在使用 smtp 邮件功能的 cakephp 中遇到了这个错误

cakephp代码:

...
try{
$emailClass = new CakeEmail();
$emailClass->config(array(
'host' => 'ssl://'.$this->smtpHostName,
'port' => $this->smtpPort,
'username' => $this->smtpUserName,
'password' => $this->smtpPassword,
'transport' => 'Smtp'
));
$emailClass->from(array($this->from => $this->fromName));
$emailClass->to($user_email);
$emailClass->subject($subject);
$emailClass->emailFormat('html');
$contents = $emailClass->send($message_text);
if (!empty($contents))
return true;
}
catch (Exception $e){
pr($e);
}
...

错误轨迹:

 ...
[_messageTemplate:protected] =>
[message:protected] => Unable to connect to SMTP server.
[string:Exception:private] =>
[code:protected] => 500
[file:protected] => /opt/lampp/htdocs/site/lib/Cake/Network/Email/SmtpTransport.php
[line:protected] => 96
[trace:Exception:private] => Array
...

已验证 smtp 配置是否正确,因为我能够使用 phpmail 发送电子邮件

...
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'port' => 25,
'debug' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);
...

我不确定它是否与 cakephp 的配置有关,因为电子邮件代码在另一台服务器上工作。

尝试过:

fsockopen('ssl://hosthere', porthere);

SSL 问题?

最佳答案

加超时后试试,希望能解决这个问题!

...
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'port' => 25,
'debug' => true,
**'timeout' => 30,**
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);
...

关于php - 无法连接到 SMTP 服务器。在 CakePHP 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20534375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com