Email 如何在cakephp中一次发送多封电子邮件
我需要一次发送多封电子邮件,任何一封都可以举个例子吗?或者有什么想法? 我需要一次向所有网站用户发送邮件(所有用户的邮件内容相同) 目前我正在for循环中使用以下代码Email 如何在cakephp中一次发送多封电子邮件,email,cakephp,cakephp-1.3,cakephp-1.2,bulk,Email,Cakephp,Cakephp 1.3,Cakephp 1.2,Bulk,我需要一次发送多封电子邮件,任何一封都可以举个例子吗?或者有什么想法? 我需要一次向所有网站用户发送邮件(所有用户的邮件内容相同) 目前我正在for循环中使用以下代码 $this->Email->from = '<no-reply@noreply.com>'; $this->Email->to = $email; $this->Email->subject = $subje
$this->Email->from = '<no-reply@noreply.com>';
$this->Email->to = $email;
$this->Email->subject = $subject ;
$this->Email->sendAs = 'html';
$this->Email->from='';
$this->Email->to=$Email;
$this->Email->subject=$subject;
$this->Email->sendAs='html';
我认为您有两种可能性:
foreach
假设您在users控制器中有一个函数mail\u users
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');
}
}
现在,您可以通过链接调用此方法,链接到/users/mail\u users/subject
有关更多信息,请务必阅读手册。在Cakephp 2.0中,我使用了以下代码:
$result = $email->template($template, 'default')
->emailFormat('html')
->to(array('first@gmail.com', 'second@gmail.com', 'third@gmail.com')))
->from($from_email)
->subject($subject)
->viewVars($data);
试试这个:
$tests = array();
foreach($users as $user) {
$tests[] = $user['User']['email'];
}
$mail = new CakeEmail();
$mail->to($tests)
->from('<no-reply@noreply.com>')
->subject('ALERT')
->emailFormat('html')
->send('Your message here');
$tests=array();
foreach($users作为$user){
$tests[]=$user['user']['email'];
}
$mail=new-CakeEmail();
$mail->to($tests)
->从(“”)
->主语('ALERT')
->emailFormat('html')
->发送(“您的信息在此”);
“->to()”和一系列电子邮件地址一起工作,但需要注意的是,电子邮件将以“收件人”字段中的地址列表的形式发送,而不是像人们期望的那样发送单个电子邮件。考虑使用'-> bcc'(),以防你不想把你网站上的每一个用户发送到你网站上的每个用户的电子邮件地址。它的静态方式不是动态的电子邮件。如果是静态数组,您可以传递动态数组。。这些都是非常基本的。你到底想要什么?因为我直接使用Cakephp列表查询从数据库中获取了数千个用户,并将其传递给参数。。你这样做是不公平的,所以这不是正确的做法。。我是根据我的工作经验告诉你的。。但是你否决了我的答案。。哈哈哈,这不是一个标准的方式。。使用foreach你能解释一下标准方法吗?不要使用foreach。。如果你有100000个用户,那么这不是正确的格式。获取用户的电子邮件id并传入到字段
$tests = array();
foreach($users as $user) {
$tests[] = $user['User']['email'];
}
$mail = new CakeEmail();
$mail->to($tests)
->from('<no-reply@noreply.com>')
->subject('ALERT')
->emailFormat('html')
->send('Your message here');