2
votes

I need to send two different emails one for the admin and the other email is a confirmation email for the user to confirm that we have received his request. I don't know how can I exactly send different emails to different email addresses in the same action in cakephp.

Code :

Controller

    $Email = new CakeEmail('notifications');

    $result =           $Email->to(array('[email protected]'))                  
                        ->subject(__("Request Notification))
                        ->send($message);


  if($result){

                $this->redirect('/pages/thankyou'); 
                $companymsg= "Dear,Thank you for you interest we will contact you soon."
                $Email = new CakeEmail('usernotifications');

                $Email->to(array($email))                   
                      ->subject(__(" Request"))
                      ->send($companymsg);


}

Email Configuration

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


    public $usernotifications = array(
    'transport' => 'Mail',
    'from' => array('[email protected]' => 'My Project'),
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
    'emailFormat' => 'html',
);
1
double quote is missing in ->subject(__("Request Notification)) . This should throw a fatal error but you are saying its sending one of your email. Put a double quote and comment the $this->redirect('/pages/thankyou'); line and try. Do let me know if it still does not work.amarjeet kumar
Still sending one email onlyAlaa Mohammad
Try setting Configure::write('debug', 2); in your controller and see what errors are there. Seems there is some error while sending second email. Do let me know the error.amarjeet kumar
make sure variable $email having correct email address.Vivek S

1 Answers

0
votes
Try:
$Email = new CakeEmail('notifications');
$result = $Email->to(array('[email protected]'))                  
->subject(__("Request Notification))
->send($message);
$companymsg= "Dear,Thank you for you interest we will contact you soon."
$Email = new CakeEmail('usernotifications');
$Email->to(array($email))                   
->subject(__(" Request"))
->send($companymsg);
$this->redirect('/pages/thankyou');