email - 如何在cakephp中一次发送多封电子邮件

标签 email cakephp cakephp-1.3 cakephp-1.2 bulk

我需要一次发送多封电子邮件,有人可以举个例子吗?或任何想法?
我需要一次向所有站点用户发送邮件(邮件内容对所有人都相同)

目前我在 for 循环中使用以下代码

        $this->Email->from     = '<no-reply@noreply.com>';
        $this->Email->to       =  $email;
        $this->Email->subject  =   $subject ;
        $this->Email->sendAs   = 'html'; 

最佳答案

我认为你有两种可能性:

foreach

假设您有一个函数 mail_users在您的 UsersController

function mail_users($subject = 'Sample subject') {
    $users = $this->User->find('all', array('fields' => array('email'));
    foreach ($users as $user) {
        $this->Email->reset();
        $this->Email->from     = '<no-reply@noreply.com>';
        $this->Email->to       =  $user['email'];
        $this->Email->subject  =  $subject ;
        $this->Email->sendAs   = 'html';
        $this->Email->send('Your message body');
    }
}

在这个函数中 $this->Email->reset()很重要。

使用密件抄送
function mail_users($subject = 'Sample subject') {
    $users = $this->User->find('all', array('fields' => array('email'));
    $bcc = '';
    foreach ($users as $user) {
        $bcc .= $user['email'].',';
    }
    $this->Email->from     = '<no-reply@noreply.com>';
    $this->Email->bcc      = $bcc;
    $this->Email->subject  = $subject;
    $this->Email->sendAs   = 'html';
    $this->Email->send('Your message body');
}

现在,您可以使用指向 /users/mail_users/subject 的链接调用此方法。

有关更多信息,请务必阅读 Email Component 上的手册。 .

关于email - 如何在cakephp中一次发送多封电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6211992/

相关文章:

cakephp - CAKEPHP 2.0 中管理员和用户的 session 超时不同。是否可以?

CakePHP HABTM 表单提交

php - 如何在删除选定查询参数的同时使用 cakephp 重建 url?

php - CakePHP - Html->link - 为什么使用 controller=> 和 action=> 而不仅仅是 controller/action

php - CakePHP 用 MAX 查找

java - 使用 JavaMail 解析 MIME 消息

python - 在 Django 中将静态文件中的图像添加到多部分电子邮件中

ios - 如何在 firebase 中更新当前用户的电子邮件和密码(在用户节点和身份验证中)?

php - jquery.validate 不适用于选择框

email - 在 VB6 中使用 SSL 发送电子邮件