使用 Codeigniter 3,我有一个网络表单,一旦提交表单,它就会向站点管理员发送一封电子邮件 - 这按预期工作。
我正在使用电子邮件模板,一旦提交表单,就会发送模板 1(发送给站点管理员)。我现在想同时发送模板 2(到提交者的电子邮件地址)。
除了电子邮件介绍文本和主题 - 详细信息外,电子邮件将包含相同的内容;
'嗨,网站上有一个新项目被请求,......'
'嗨,这是您在网站上要求的项目,......'
我目前的代码如下;
public function sendRequest() {
$this->load->library('email');
$from_email = $this->input->post('email');
$to_email = '[email protected]';
$subject = 'New Item Request - Admin Copy';
$name = $this->input->post('name');
$comment = $this->input->post('comment');
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->subject($subject);
$data = array(
'name' => $name,
'from' => $from_email,
'comment' => $comment,
);
// send email template 1
$this->email->message($this->load->view('template/email/item_request_template', $data, true));
// send email template 2 to submitter - how?
// change $subject to 'New Item Request - User Copy';
if($this->email->send()) {
// send the $data to my email template
$data = array(
'item_request_name' => $this->input->post('name'),
'item_request_email' => $this->input->post('email'),
'item_request_comment' => $this->input->post('comment'),
);
}
}
有没有更有效的方法来做到这一点?
您只需首先重复发送电子邮件所需的所有步骤。唯一的区别是,对于第二次调用,您需要调用并重置所有必需的配置选项。
public function sendRequest() {
$this->load->library('email');
$from_email = $this->input->post('email');
$to_email = '[email protected]';
$subject = 'New Item Request - Admin Copy';
$name = $this->input->post('name');
$comment = $this->input->post('comment');
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->subject($subject);
$data = array(
'name' => $name,
'from' => $from_email,
'comment' => $comment,
);
// send email template 1
$this->email->message($this->load->view('template/email/item_request_template', $data, true));
// send email template 2 to submitter - how?
// change $subject to 'New Item Request - User Copy';
if($this->email->send()) {
$this->email->clear(TRUE); // Pass TRUE as an argument if you are sending attachments
$this->email->from($from_email); // Update for second email
$this->email->to($to_email); // Update for second email
$this->email->subject($subject); // Update for second email
// send the $data to my email template
$data = array(
'item_request_name' => $this->input->post('name'),
'item_request_email' => $this->input->post('email'),
'item_request_comment' => $this->input->post('comment'),
);
$this->email->message($this->load->view('template/email/item_request_template_2', $data, true));
$this->email->send();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句