php - CakeEmail - 设置多个收件人
问题描述
我有下一个问题。我一直在尝试将多个收件人放入我设置的变量中,但邮件没有被触发。我只用一个收件人对此进行了测试,它可以工作。当我尝试再添加一个时,电子邮件将不会发送。这是第一个定义简单电子邮件发送的函数。这位于我AppController.php
的电子邮件发送是使用指定的类 CakeEmail 完成的。
public function sendSimpleMail($to, $subject, $body, $to_copy = "") {
$to = trim($to);
$replay_to = EMAIL_REPLY;
try {
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();
if($to_copy == ""){
$email->config('smtp')
->to($to)
->subject($subject)
->replyTo($replay_to)
->emailFormat('html');
}
else{
$email->config('smtp')
->to($to)
->subject($subject)
->replyTo($replay_to)
->bcc($to_copy)
->emailFormat('html');
}
$email->send($body);
return true;
} catch (Exception $e) {
$error = $e->getMessage();
return $error;
}
}
此外,我将附上我准备电子邮件并在通过表单触发 ajax 请求时将其发送给收件人的功能。
public function wallet_request_ajax($email_callback){
$this->autoRender = false;
$d = $this->request->data;
if(empty($d['date'])){
return json_encode([
'id' => 400,
'txt' => __('Please, insert a date for the department to call you.')
]);
}
if(empty($d['time'])){
return json_encode([
'id' => 400,
'txt' => __('Please specify an hour for the call.')
]);
}
if(empty($d['phone'])){
return json_encode([
'id' => 400,
'txt' => __('Please, specify a phone number.')
]);
}
$existId = $this->Member->find('first', [
'recursive' => -1,
'fields' => ['id', 'name', 'surname'],
'conditions' => [
'md5(id)' => $d['id']
]
]);
if(empty($existId)){
return json_encode([
'id' => 400,
'txt' => __('Unexpected error. Contact with '. TELEPHONE) //TELEPHONE constant
]);
}
$member_name = $existId['Member']['name'];
$member_surname = $existId['Member']['surname'];
$this->set(compact('member_name', 'member_surname'));
$final_name = $member_name . " ".$member_surname;**
$this->loadModel('PhoneCall');
$this->PhoneCall->create();
if($this->PhoneCall->save([
'phone' => $d['phone'],
'id' => $existId['Member']['id'],
'date' => date('Y-m-d', strtotime($d['date'])),
'time' => $d['time']
])){
// We send the email to 'customer care'
if (PAIS === 'es'){ // if country is Spain
$to = "blabla12@hotmail.com, etc@gmail.com ,blabla@gmail.com"; // recipients
} elseif(PAIS == 'it') { // if country is Italy
$to = "etc@gmail.com"; // recipients
}elseif(PAIS === 'en'){ // if country is UK
$to = "blabla12@hotmail.com"; // recipients
}
$subject = "Activation service";
$body = "";
$body .= "--------Notification of activation service";
$body .= "-------<br>";
if ($final_name !== "") {
$body .= "<tr><td>Name: " . $final_name . "</td></tr><br>";
}
$body .= "----------------------------<br>";
$body .= "<tr><td>Date: " . $d['date'] . "<br></td></tr>";
$body .= "----------------------------<br>";
$body .= "<tr><td>".__('Time'). ":" . $d['time'] . "<br></td></tr>";
$body .= "----------------------------<br>";
$body .= "<tr><td>Phone: " . $d['phone'] . "</td></tr><br>";
$body .= "----------------------------<br>";
$body .= "----------------------------<br>";
$email_callback = $this->sendSimpleMail($to, $subject, $body);
return json_encode([
'id' => 200,
'txt' => __('We will call you the specified time.')
]);
}
如果你们中的任何人对此事有任何想法,那将非常感激。我有点卡住,因为我想尝试包括其他收件人,但不幸的是我认为它必须与 CakeEmail 类有某种兼容性。干杯
解决方案
如果您需要向多个收件人发送电子邮件,则需要将它们指定为数组。
$email->config('smtp')
->to( array('first@email.com', 'second@email.com'));
从文档
'to':电子邮件或目的地数组。
推荐阅读
- r - 如何在矩阵上循环操作?
- javascript - 大型 mailto 链接无法在 Chrome 中打开
- javascript - 当我们提到(@)机器人时,如何使 Discord.js 机器人响应本地图片?
- r - 按名称减去数据框的列
- variables - 为什么一个子程序的变量正在访问另一个子程序的值?
- python - 尝试将歌曲添加到使用 spotify api 时收到 404
- react-native - 如何在 React-Native 中进行 API 登录认证
- swift - 听写后用三指点击执行撤消时应用程序崩溃
- json - Flutter应用程序中的Json解析花费了太多时间
- c# - 当连续询问两个具有多提示答案的问题并且 rankerType 为“questionOnly”时,QnAMaker 不返回任何答案