Reputation: 780
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' => '[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',
);
}
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;
}
Upvotes: 0
Views: 355
Reputation: 449
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
Upvotes: 1