我想将视图传递给一个字符串,并使用 codeigniter 在电子邮件中作为邮件正文传递。有什么建议么?
I want to pass view to a string and to pass as a message body in email using codeigniter. Any suggestions?
我想在注册用户时发送电子邮件模板。所以我为它创建了视图,以便可以根据需要使用不同的视图。比如注册和忘记密码两种不同的看法。
public function email($data, $type){
$smtp = $this->smtp_model->smtp_data();
$config['protocol'] = 'smtp';
$config['smtp_host'] = $smtp->host;
$config['smtp_port'] = $smtp->port;
$config['smtp_user'] = $smtp->username;
$config['smtp_pass'] = $smtp->password;
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = '\r\n';
$this->email->initialize($config);
$this->email->clear(TRUE);
$this->email->from($smtp->from_email, $smtp->from_name);
$this->email->to($data->email);
$this->email->subject(SITENAME.' - '.$type);
// Here it should return html from the view
$mail_message = $this->email_template($data, 'registration');
echo $mail_message;die;//but it is printing empty
$this->email->message($mail_message);
$this->email->send();
}
public function email_template($data, $type){
$email_body = $this->load->view('email/include/head');
// Below are the condition on basis of it view will be selected
if($type == 'registration')
$email_body = $this->load->view('email/user_registration', $data);
if($type == 'forgot_password')
$email_body = $this->load->view('email/forgot_password', $data);
//Need to pass view to variabel which will be returned to above function
$email_body = $this->load->view('email/include/footer');
return $email_body;
}
您需要将 true
作为第三个参数传递,因为您将此 HTML 存储在变量 $email_body
.
中
希望对您有所帮助!!
希望对你有帮助:
将$this->load->view()
的第三个参数设置为TRUE
如果将参数设置为 TRUE(布尔值),它将 return 数据。默认行为是假的,
email_template
方法应该是这样的:
public function email_template($data, $type)
{
$email_body = $this->load->view('email/include/head','',TRUE);
if($type == 'registration')
{
$email_body += $this**strong text**->load->view('email/user_registration', $data,TRUE);
}
if($type == 'forgot_password')
{
$email_body += $this->load->view('email/forgot_password', $data,TRUE);
}
$email_body += $this->load->view('email/include/footer','',TRUE);
return $email_body;
}
更多:https://www.codeigniter.com/user_guide/general/views.html#returning-views-as-data
我想在注册用户时发送电子邮件模板。所以我为它创建了视图,以便可以根据需要使用不同的视图。比如注册和忘记密码两种不同的看法。
public function email($data, $type){
$smtp = $this->smtp_model->smtp_data();
$config['protocol'] = 'smtp';
$config['smtp_host'] = $smtp->host;
$config['smtp_port'] = $smtp->port;
$config['smtp_user'] = $smtp->username;
$config['smtp_pass'] = $smtp->password;
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = '\r\n';
$this->email->initialize($config);
$this->email->clear(TRUE);
$this->email->from($smtp->from_email, $smtp->from_name);
$this->email->to($data->email);
$this->email->subject(SITENAME.' - '.$type);
// Here it should return html from the view
$mail_message = $this->email_template($data, 'registration');
echo $mail_message;die;//but it is printing empty
$this->email->message($mail_message);
$this->email->send();
}
public function email_template($data, $type){
$email_body = $this->load->view('email/include/head');
// Below are the condition on basis of it view will be selected
if($type == 'registration')
$email_body = $this->load->view('email/user_registration', $data);
if($type == 'forgot_password')
$email_body = $this->load->view('email/forgot_password', $data);
//Need to pass view to variabel which will be returned to above function
$email_body = $this->load->view('email/include/footer');
return $email_body;
}
您需要将 true
作为第三个参数传递,因为您将此 HTML 存储在变量 $email_body
.
希望对您有所帮助!!
希望对你有帮助:
将$this->load->view()
的第三个参数设置为TRUE
如果将参数设置为 TRUE(布尔值),它将 return 数据。默认行为是假的,
email_template
方法应该是这样的:
public function email_template($data, $type)
{
$email_body = $this->load->view('email/include/head','',TRUE);
if($type == 'registration')
{
$email_body += $this**strong text**->load->view('email/user_registration', $data,TRUE);
}
if($type == 'forgot_password')
{
$email_body += $this->load->view('email/forgot_password', $data,TRUE);
}
$email_body += $this->load->view('email/include/footer','',TRUE);
return $email_body;
}
更多:https://www.codeigniter.com/user_guide/general/views.html#returning-views-as-data