gpt4 book ai didi

php - CakePHP : Send email to multiple addresses

转载 作者:可可西里 更新时间:2023-11-01 13:40:03 24 4
gpt4 key购买 nike

我想用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com