CAKEPHP:以简单的方式向两个用户发送电子邮件

时间:2017-06-14 08:20:51

标签: php email cakephp

需要帮助!

使用CakePHP,我需要向两个用户发送相同的电子邮件,我在论坛中引用了这个东西,他们都建议声明一组电子邮件,通过for循环可以实现它。但是我想简单地说,不想再循环,如何在那里再添加一个电子邮件帐户。对于(例如abc@account.com)需要发送相同的电子邮件

我为一位用户发送电子邮件的行为是......(代码下方)

$emailadmin->template('learn_payment', 'default')
    ->to([$this->request->session()->read('Auth.User.email') => Configure::read('app_title')])
    ->from([Configure::read('support_email') => Configure::read('app_title')])
    ->subject(sprintf('You have subscribed a learning on %s', Configure::read('app_title')))
    ->emailFormat('both')
    ->send(); 

提前致谢!

1 个答案:

答案 0 :(得分:0)

你可以用两种方式:

$mails = array();
foreach($users as $user)
{
    $mails[] = 'email1@email1.com';
    $mails[] = 'email2@email2.com';
}

$emailadmin->template('learn_payment', 'default')
      ->to($mails)
      ->from([Configure::read('support_email') => Configure::read('app_title')])
      ->subject(sprintf('You have subscribed a learning on %s', Configure::read('app_title')))
      ->emailFormat('both')
      ->send(); 

或者这样:

$emailadmin = new CakeEmail();

foreach($users as $user) {
    $emailadmin->addTo($user['User']['email']);
}

$emailadmin->template('learn_payment', 'default')
          ->from([Configure::read('support_email') => Configure::read('app_title')])
          ->subject(sprintf('You have subscribed a learning on %s', Configure::read('app_title')))
          ->emailFormat('both')
          ->send();