PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

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

 February 16, 2022     cakephp, cakephp-2.0, email, php     No comments   

Issue

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

Solution

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



Answered By - polyte
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing