我在很多天里都遇到过这个问题。请帮忙。我已经关注了cakephp文档。但无法解决问题。
Could not send email: unknown
Error: An Internal Error Has Occurred.
以下是配置emai.php
<?php
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => '[email protected]',
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('site@localhost' => 'SevenRocks'),
'host' => 'ssl://smtp.sevenrocks.in',
'port' => 465,
'timeout' => 30,
'username' => '[email protected]',
'password' => 'developerofsevenrocks',
'client' => null,
'log' => true,
'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
以下是控制器中的代码
$email = new CakeEmail();
$email->emailFormat('html');
$email->from(array($from_email => SITE_NAME));
$email->to($to);
$email->subject($subject);
if ($files)
{
$email->attachments($files);
}
if ( !$email->send($content) )
{
return false;
}
第一:调试CakePHP 2x应用程序在app/Config/core.php
中搜索调试并将其更改为Configure::write('debug', 2);
以查看完整的错误消息。
第二:某些提供商可能会阻止您直接通过PHP发送邮件(默认邮件配置)。更好的解决方案可能是使用您在email.php
中提供的smtp配置。要使用smtp配置,请将控制器代码更改为:
$email = new CakeEmail('smtp');
$email->emailFormat('html');
$email->to($to);
$email->subject($subject);
有关更多信息,请参阅https://book.cakephp.org/2.0/en/core-utility-libraries/email.html#configuration