我想在注册用户时发送电子邮件模板。所以我为它创建了视图,以便可以根据需要使用不同的视图。就像注册和忘记密码一样,有两种不同的视图。
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;
}