简体   繁体   中英

Cakephp 2.x email not working, Why this Error comes

I struck on this problem on many days. Please help. I have followed the cakephp documentation. but could not resolve issue.

Could not send email: unknown
Error: An Internal Error Has Occurred.    

Following is Configuration 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',
    );

}

Following is code in controller

$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;
}

First: to debug CakePHP 2x applications search for debug in your app/Config/core.php and change it to Configure::write('debug', 2); to see the full error message.

Second: Some providers may prevent you from sending Mails via PHP directly ( default mail config). A better solution may to use the smtp configuration you provided in email.php . To use your smtp configuration change your controller code to:

$email = new CakeEmail('smtp');

$email->emailFormat('html');
$email->to($to);
$email->subject($subject);

For more Info see https://book.cakephp.org/2.0/en/core-utility-libraries/email.html#configuration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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