Php 将数据从一个视图传递到“代码点火器”中选中的复选框上的电子邮件模板视图
我正在使用代码点火器开发一个web应用程序。我正在尝试创建一个动态电子邮件模板,当我从其他视图选中复选框时,该模板将动态加载数据 以下是我的场景: 如果我选中了Php 将数据从一个视图传递到“代码点火器”中选中的复选框上的电子邮件模板视图,php,jquery,email,checkbox,codeigniter-3,Php,Jquery,Email,Checkbox,Codeigniter 3,我正在使用代码点火器开发一个web应用程序。我正在尝试创建一个动态电子邮件模板,当我从其他视图选中复选框时,该模板将动态加载数据 以下是我的场景: 如果我选中了HMO_001的复选框,那么将加载到HMO_001表中的所有数据都将传递到我的电子邮件模板,当我单击“发送”按钮时,邮件将发送给特定的房东 现在,当我选中多个复选框时,我可以通过点击按钮一次向多个房东发送电子邮件,但电子邮件是硬编码的。我试图让它充满活力,但没有成功 这是我的代码: 加载表格数据的控制器: 公共功能索引() { #代码。
HMO_001
的复选框,那么将加载到HMO_001
表中的所有数据都将传递到我的电子邮件模板,当我单击“发送”按钮时,邮件将发送给特定的房东
现在,当我选中多个复选框时,我可以通过点击按钮一次向多个房东发送电子邮件,但电子邮件是硬编码的。我试图让它充满活力,但没有成功
这是我的代码:
加载表格数据的控制器:
公共功能索引()
{
#代码。。。
$user=$this->ion\u auth->user()->row();
$data['username']=$user->username;
$data['user_id']=$user->id;
$LONDER=$this->input->post('LONDER_id');
$property=$this->input->post('property_id');
$certificate=$this->input->post('certificate_id');
如果($LONDER=''){
$LONDER=0;
}
如果($property=''){
$property=0;
}
如果($certificate==''){
$certificate=0;
}
$data['landlords']=$this->c->landordlist();
//$data['properties']=$this->c->propertyList();
$data['certificates']=$this->c->certificateList();
//$data['certified']=$this->c->certificate_List();
$data['certified']=$this->c->GetCertificateBylandOrdProperty($Lown,$property,$certificate);
//打印($data[“房东]);
//打印($data['properties');
//回声“;
public function sendMail()
{
# code...
//$data['certified'] = $this->c->getcertificateByLandlordProperty($landlord, $property, $certificate);
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['sendMail'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['sendMail'] as $selected){
//echo $selected."</br>";
}
}
}
$email_to = $this->input->post('sendMail[]');
<!-- echo "<pre>";
print_r($email_to);
echo "</pre>";
exit(); -->
$body = $this->load->view('emailTemplate/certTemplate', $data);
$this->load->library('email');
$config = array();
$config['protocol'] = 'mail';
$config['smtp_port'] = 587;
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'info@admin.com';
$config['smtp_pass'] = '**********';
$config['smtp_crypto'] = 'STARTTLS';
$config['newline'] = "\r\n"; //REQUIRED! Notice the double quotes!
$config['crlf'] = "\r\n";
$config['mailtype'] = "html";
$this->email->initialize($config);
$this->email->from('info@admin.com', 'Administrator');
$this->email->to($email_to);
$this->email->subject('Your Subject');
$this->email->message('$body');
$sent = $this->email->send();
if ($sent)
{
echo 'OK, mail send successfully';
} else {
echo $this->email->print_debugger();
}
}
//打印($data[‘证书’);
//回声“;
public function sendMail()
{
# code...
//$data['certified'] = $this->c->getcertificateByLandlordProperty($landlord, $property, $certificate);
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['sendMail'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['sendMail'] as $selected){
//echo $selected."</br>";
}
}
}
$email_to = $this->input->post('sendMail[]');
<!-- echo "<pre>";
print_r($email_to);
echo "</pre>";
exit(); -->
$body = $this->load->view('emailTemplate/certTemplate', $data);
$this->load->library('email');
$config = array();
$config['protocol'] = 'mail';
$config['smtp_port'] = 587;
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'info@admin.com';
$config['smtp_pass'] = '**********';
$config['smtp_crypto'] = 'STARTTLS';
$config['newline'] = "\r\n"; //REQUIRED! Notice the double quotes!
$config['crlf'] = "\r\n";
$config['mailtype'] = "html";
$this->email->initialize($config);
$this->email->from('info@admin.com', 'Administrator');
$this->email->to($email_to);
$this->email->subject('Your Subject');
$this->email->message('$body');
$sent = $this->email->send();
if ($sent)
{
echo 'OK, mail send successfully';
} else {
echo $this->email->print_debugger();
}
}
//退出();
$data['title']=“证书列表”;
$this->load->view('template/header',$data);
$this->load->view('certificate/certificate\u list',$data);
$this->load->view('template/footer');
}
发送邮件的控制器:
公共函数sendMail()
{
#代码。。。
//$data['certified']=$this->c->GetCertificateBylandOrdProperty($Lown,$property,$certificate);
if(isset($_POST['submit']){//在提交时运行PHP脚本
如果(!空($_POST['sendMail'])){
//循环以存储和显示单个复选框的值。
foreach($\u POST['sendMail']作为$selected){
//echo$已选定。“”;
}
}
}
$email_to=$this->input->post('sendMail[]);
$body=$this->load->view('emailTemplate/certTemplate',$data);
$this->load->library('email');
$config=array();
$config['protocol']='mail';
$config['smtp_port']=587;
$config['smtp_host']='smtp.office365.com';
$config['smtp_用户']='info@admin.com';
$config['smtp_pass']='***********';
$config['smtp_crypto']='STARTTLS';
$config['newline']=“\r\n”;//必需!请注意双引号!
$config['crlf']=“\r\n”;
$config['mailtype']=“html”;
$this->email->initialize($config);
$this->email->from($this)info@admin.com","署长",;
$this->email->to($email\u to);
$this->email->subject(“您的主题”);
$this->email->message(“$body”);
$sent=$this->email->send();
如果($已发送)
{
回显“确定,邮件发送成功”;
}否则{
echo$this->email->print_debugger();
}
}
欢迎任何帮助,提前感谢。要制作自定义电子邮件模板,您可以这样做:
1.将每个收件人部分移动到您之前创建的foreach循环中,这样您就可以知道每个未发送给收件人的电子邮件。
2.在消息
$body
上添加第三个TRUE
参数(以字符串形式返回数据,而不是将其发送到浏览器)。3.添加
clear()
方法,使每个收件人只接收其自定义邮件(以防止在每个收件人上显示所有收件人)
希望能有帮助
public function sendMail()
{
# code...
//$data['certified'] = $this->c->getcertificateByLandlordProperty($landlord, $property, $certificate);
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['sendMail'])){
$this->load->library('email');
$config = array();
$config['protocol'] = 'mail';
$config['smtp_port'] = 587;
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'info@admin.com';
$config['smtp_pass'] = '**********';
$config['smtp_crypto'] = 'STARTTLS';
$config['newline'] = "\r\n"; //REQUIRED! Notice the double quotes!
$config['crlf'] = "\r\n";
$config['mailtype'] = "html";
$this->email->initialize($config);
// Loop to store and display values of individual checked checkbox.
foreach($_POST['sendMail'] as $selected){
$data['email_to'] = $selected;
$body = $this->load->view('emailTemplate/certTemplate', $data, TRUE); // the TRUE parameter will return data as a string instead of sending it to browser (access recipient email on certTemplate with $email_to variable)
$this->email->clear();
$this->email->from('info@admin.com', 'Administrator');
$this->email->to($email_to);
$this->email->subject('Your Subject');
$this->email->message($body); // remove quotes from $body
$sent = $this->email->send();
if ($sent)
{
echo 'OK, mail send successfully';
} else {
echo $this->email->print_debugger();
}
}
}
}
}