我有下一个问题。我一直在尝试将多个收件人放入我设置的变量中,但邮件没有被触发。我只用一个收件人对此进行了测试,它可以工作。当我尝试再添加一个时,电子邮件将不会发送。这是第一个定义简单电子邮件发送的函数。这位于我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 类有某种兼容性。干杯