rickl
rickl

Reputation: 91

cakephp 2 CakeEmail Could not send email error

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' => '[email protected]'
        );
}

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

Upvotes: 0

Views: 8380

Answers (3)

Fury
Fury

Reputation: 4776

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 protected]' => '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

Upvotes: 0

Arun Jain
Arun Jain

Reputation: 5464

Try with the following configuration in email.php

public $default = array(
    'transport' => 'Mail',
    'from' => '[email protected]',
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8'
);

Upvotes: 0

kicaj
kicaj

Reputation: 2968

You must add more configuration in EmailConfig.

Look at my code:

class EmailConfig {    
    public $fast = array(    
        'transport' => 'Smtp',    
        'from' => array('[email protected]' => 'Test Mail name sender'),    
        'host' => 'ssl://smtp.gmail.com',    
        'port' => 465,    
        'username' => '[email protected]',    
        'password' => 'password');    
}

And in Controller:

CakeEmail::deliver('[email protected]', 'Subject', 'Content');

That's it!

Upvotes: 1

Related Questions