在cakephp中发送不同的电子邮件

时间:2015-07-21 08:39:53

标签: php email cakephp cakephp-2.0

我需要为管理员发送两封不同的电子邮件,另一封电子邮件是确认电子邮件,供用户确认我们已收到他的请求。我不知道如何在cakephp的同一操作中将不同的电子邮件发送到不同的电子邮件地址。

代码:

控制器

    $Email = new CakeEmail('notifications');

    $result =           $Email->to(array('admin@example.com'))                  
                        ->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);


}

电子邮件配置

public $notifications = array(
        'transport' => 'Mail',
        'from' => array('notifications-noreply@example.com' => '(Notification)'),
        'charset' => 'utf-8',
        'headerCharset' => 'utf-8',
        'emailFormat' => 'html',
    );


    public $usernotifications = array(
    'transport' => 'Mail',
    'from' => array('no-reply@example.com' => 'My Project'),
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
    'emailFormat' => 'html',
);

1 个答案:

答案 0 :(得分:0)

Try:
$Email = new CakeEmail('notifications');
$result = $Email->to(array('admin@example.com'))                  
->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');