我想用 CakeEmail 发送一封电子邮件到多个地址(在我的网站上注册的人的电子邮件地址)。
这是我使用的代码:
public function send($d){
$this->set($d);
if($this->validates()){
App::uses('CakeEmail','Network/Email');
$users = $this->User->find('all');
$this->set($tests);
foreach($users as $user)
{
$tests .= '"'.$user['User']['email'].'",';
}
$mail = new CakeEmail();
$mail
->to(array($tests))
->from(array('test2@test.fr' => 'Hello'))
->subject('ALERTE')
->emailFormat('html')
->template('ouverture')->viewVars($d);
return $mail->send();
}
else{
return false;
}
}
这是我的错误:
Invalid email : ""test@test.com","test@test.fr","
最佳答案
尝试
$tests = array();
foreach($users as $user)
{
$tests[] = $user['User']['email'];
}
$mail = new CakeEmail();
$mail->to($tests)
->from(array('test2@test.fr' => 'Hello'))
->subject('ALERTE')
->emailFormat('html')
->send('Your message here');
关于php - CakePHP : Send email to multiple addresses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23371167/