问题
I am trying to get CakeEmail working and I am getting a "Could not send email" Internal Error.
The last line of the stack trace is
CORE/Cake/Network/Email/MailTransport.php line 47 -> MailTransport->_mail(string,string,string,string,null)
In my email.php config I have
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'no-reply@xxxxx.com.au'
);
}
I receive my email address from a form and am trying to send an email to the subscriber. My code is as follows
$email_addr = $subs_data['Subscriber']['subscriber'];
$Email = new CakeEmail('default');
$Email->emailFormat('html')
->template('welcome')
->to($email_addr)
->subject('New Subscription')
->send();
I have done some testing and the value in $email_addr is exactly what is coming from the form and is a valid Email address.
I have a template in View/Emails/html/welcome.ctp that for now is just a very basic message
Looking at the stack trace and line 47 in MailTransport.php I have found the error appears to be to do with the "to" email address. I can not see what is wrong with it though. I have looked at a lot of examples and as far as I can tell I am not doing anything wrong.
I would appreciate any help so I could get this application finished.
Kind Regards
Richard
回答1:
You must add more configuration in EmailConfig.
Look at my code:
class EmailConfig {
public $fast = array(
'transport' => 'Smtp',
'from' => array('test_mail@gmail.com' => 'Test Mail name sender'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'test_mail@gmail.com',
'password' => 'password');
}
And in Controller:
CakeEmail::deliver('to@gmail.com', 'Subject', 'Content');
That's it!
回答2:
Try with the following configuration in email.php
public $default = array(
'transport' => 'Mail',
'from' => 'abc@my-domain.com',
'charset' => 'utf-8',
'headerCharset' => 'utf-8'
);
回答3:
Did you load email library into your controller or AppController/?
App::uses('CakeEmail', 'Network/Email');
if you are sure that your email config is correct so try to test it on live to see if it works.
and try to configure your email with smtp to make sure your email is sending correctly.
public $smtp = array(
'transport' => 'Smtp',
'from' => array('email@test.com' => 'Company name'),
'host' => 'mail.test.com',
'port' => 25,
'timeout' => 30,
'username' => 'email',
'password' => 'password',
'client' => null,
'log' => false,
);
and for set the template look at my answer here:
Email template not using themed version
来源:https://stackoverflow.com/questions/17669012/cakephp-2-cakeemail-could-not-send-email-error