0
<?php 

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


        ));

         function sendEmail() {
            $this->Email->to = 'Neil <neil6502@gmail.com>';
            $this->Email->subject = 'Cake test simple email';
            $this->Email->replyTo = 'neil6502@gmail.com';
            $this->Email->from = 'Cake Test Account <neil6502@gmail.com>';
            //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.

teacher
  • 1,005
  • 3
  • 15
  • 27

4 Answers4

0
/* Auf SMTP-Fehler prüfen */
 $this->set('smtp_errors', $this->Email->smtpError);
thegrunt
  • 1,054
  • 1
  • 11
  • 22
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' => 'my@gmail.com',
    '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('me@example.com' => 'My Site'))
    ->to('you@example.com')
    ->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');
Brett Stewart
  • 488
  • 3
  • 8
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

Community
  • 1
  • 1
Lakhan
  • 12,328
  • 3
  • 19
  • 28
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@example.com> you should use email@example.com.

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.

wrdevos
  • 2,029
  • 16
  • 19