0
<?php 

    class EmailsController extends AppController
    {
        var $uses=null;
        var $components=array(
                'Email'=>array(
                    'delivery'=>'smtp',
                    'smtpOptions'=>array(
                      'host'=>'ssl://smtp.google.com',
                      'username'=>'[email protected]',
                      'password'=>'password',
                      'port'=>465
                      )


        ));

         function sendEmail() {
            $this->Email->to = 'Neil <[email protected]>';
            $this->Email->subject = 'Cake test simple email';
            $this->Email->replyTo = '[email protected]';
            $this->Email->from = 'Cake Test Account <[email protected]>';
            //Set the body of the mail as we send it.
            //Note: the text can be an array, each element will appear as a
            //seperate line in the message body.
            if ( $this->Email->send('Here is the body of the email') ) {
                $this->Session->setFlash('Simple email sent');
            } else {
                $this->Session->setFlash('Simple email not sent');
            }
            $this->redirect('/');
            } 





    }


?>

above code is my controller responsible for sending emails...

but when i run this function sendEmail() using url http://localhost/authentication/emails/sendemail it shows nothing not even single error or any response... complete blank page. I don't know the reason.

4 Answers 4

0

I think I had the same issue a while ago. It might be that you need to change the to address into a value that holds just the address, so instead of Name <[email protected]> you should use [email protected].

You can check for errors by logging (or debugging) the smtp errors with:

$this->log($this->Email->smtpError, 'debug');

or

debug($this->Email->smtpError);

Good luck. Hope this helps.

0
/* Auf SMTP-Fehler prüfen */
 $this->set('smtp_errors', $this->Email->smtpError);
1
  • A bit of an explanation (in english) would be nice. Oct 4, 2013 at 2:43
0

I would add the Email Config to your email.php file located in /app/Config/email.php , if it doesn't exist copy email.php.default to email.php, Change the smtp settings there

public $smtp = array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'username' => '[email protected]',
    'password' => 'secret'
);

At the top of your Controller above class EmailsController extends AppController add,

App::uses('CakeEmail', 'Network/Email');

Then in your function sendEmail() try,

$Email = new CakeEmail();
$Email->from(array('[email protected]' => 'My Site'))
    ->to('[email protected]')
    ->subject('About')
    ->send('My message');

To test emails what I usually do is send them to the Cake Logs,

**In /app/Config/email.php, include: ( The log output should be /app/tmp/logs/debug.log )

public $test = array(
  'log' => true
);

Also doing this add 'test' to your $Email variable like,**

$Email = new CakeEmail('test');
0

Actually in my case : I got a error message "SMTP server did not accept the password."

After that i follow the below link and issue has been resolved : Step1 : https://blog.shaharia.com/send-email-from-localhost-in-cakephp-using-cakeemail/ Step2 : Sending Activation Email , SMTP server did not accept the password

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.