how to send an email to a user in cakephp 2.x
NickName:Ernest Mwesha Ask DateTime:2015-06-11T06:11:59

how to send an email to a user in cakephp 2.x

I will greatly appreciate with all my heart if an expert would help me on how to send an email to a user. am building a registration system. after a user successfully applies for registration, the admin must approve and at the click of the approve button, an email is send to the user and user details are saved in the approved table. Here is the approve action in the applicationsController.

    public function approve($student_id = null) {

   if ($this->request->is('post')) 
      $application = $this->Application->findById($student_id);
       $approved['Approved'] = $application['Application'];
       $approved['Approved']['student_id'] = $approved['Approved']['student_id'];

       $status = array('Application.status' => 'approved');
       unset($application['Application']['id']);
       unset($application['Application']['receipts']);
       $this->loadModel('Approved');
       $this->Approved->create();
       if ($this->Approved->save($approved)) {
          if ($this->Approved->saveField('status', 'approved')){
          $this->Session->setFlash(__('The student has been approved'));


          $email=$this->request->data['Application']['email'];
          $this->Email->to = $email;
          $this->Email->subject = 'Registration request approval';
          $this->Email->from = '[email protected]';
          $this->Email->template = 'template';


          $this->Email->smtpOptions = array(
           'port' => '465',
           'timeout' => '30',
           'host' => 'ssl://smtp.gmail.com',
           'username' => '[email protected]',
           'password' => 'mweshaernest',
            );

          $this->Email->delivery = 'smtp';
          if($this->Email->send()){

            return true;
          }
          else{

            echo $this->Email->smtpError;
          }

       $this->Application->delete($student_id);
      $this->redirect(array('action' => 'index')); }
    } else {
       $this->Session->setFlash(__('The student could not be approved.'));
   }

   $this->set('title_for_layout', 'Approved Requests');
}

after clicking the approved button i get the following error:

Notice (8): Undefined index: Application [APP\Controller\ApplicationsController.php, line 120]

You need to specify at least one destination for to, cc or bcc. Error: An Internal Error Has Occurred.

.....bot the student gets approved and placed in the approved table

Copyright Notice:Content Author:「Ernest Mwesha」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30768204/how-to-send-an-email-to-a-user-in-cakephp-2-x

Answers
Chris Vogt 2015-06-11T23:37:33

Review u2460470's answer to point you in the right direction for generating emails with CakePHP.\n\nMake sure you have a mail server setup to handle the processing of emails. You might already have one setup locally, something like SquirrelMail, or you may prefer to use a managed, hosted provider (like Gmail). You can find examples of configuring CakePHP to send mail through Gmail in the CakeEmail documentation.\n\nI've had great experiences using Postmark to handle transactional emails. There is a nice plugin, maurymmarques/postmark-plugin, you can use to easily setup Postmark for your CakePHP app.",


More about “how to send an email to a user in cakephp 2.x” related questions

CakePHP passing variables to send email with CakeEmail

In CakePHP 2.x how can I create variables in a form in order to pass it to the CakeEmail function? I currently have a php file 'email.php' that has a form with inputs 'to', 'subject' and 'message'...

Show Detail

How to send an email in background with CakePHP?

That's it, how can I send an email in background with CakePHP, preferable using the out-of-the-box Email component? EDIT: with in background I mean in another thread, or at least allowing the cont...

Show Detail

Email Not Send to Multiple User Cakephp

I want to send email to all user in database users. I use cakePHP, when i try the error is : the email just send to first user in array this is EmailTemplatesController.php public function

Show Detail

cakephp send batch email with dynamic content

I had a strange problem with email sending through cakephp and postmark. I have installed postmark-cakephp library in my cakephp application. I'm able to send email to single user and able to send...

Show Detail

how to send an email to a user in cakephp 2.x

I will greatly appreciate with all my heart if an expert would help me on how to send an email to a user. am building a registration system. after a user successfully applies for registration, the ...

Show Detail

How to send an email to the user when performing login in cakephp

I do not have any knowledge about cakephp mail so explain the solution briefly I mean what to do and how to do from the beginning. From the cakephp official side I just used this "use Cake\Mailer\...

Show Detail

Email is not send in CakePHP

I am working with CakePHP version 1.3.13. Here, I want to send mail. So I have written code like this : function send_mail_to_client() { $text = "sending mail"; App::uses('CakeEmail', '

Show Detail

Cakephp unable to send email

I want to use the cakePHP mailer system, but I am unable to send an email, I get the following error: Fatal error: Class 'CakeEmail' not found in D:... on line 100 I have the following defined i...

Show Detail

How to upload a file and attach it to email using cakephp 2.x?

I am a new learner of cakephp 2.x. I want to build a simple form for user to upload their resume files, and then send them as email attachments. Somehow I can't find a way to attach uploaded file to

Show Detail

Cakephp send email with attachment sending as 0 byte

I am dynamically generating pdf files using dompdf and attaching those to email and sending. But in mail always Im getting the attachment as 0 byte. I'am creating the files under cake's tmp folder ...

Show Detail