繁体   English   中英

Cakephp 2.x电子邮件不起作用,为什么会出现此错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM