[英]Cakephp 2.x email not working, Why this Error comes
我好幾天都在解決這個問題。 請幫忙。 我已經遵循cakephp文檔。 但無法解決問題。
Could not send email: unknown
Error: An Internal Error Has Occurred.
以下是配置emai.php
<?php
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'developer.support@sevenrocks.in',
'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' => 'developer.support@sevenrocks.in',
'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
搜索debug並將其更改為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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.