我正在通过电子邮件发送html视图。电子邮件已成功发送,但是在收到电子邮件后,图像未加载且css无法应用。 另外,我在整个HTML代码中都遇到了错误。
function send_mail() {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'demo.example.com',
'smtp_port' => 465,
'smtp_user' => 'my_smtp_username',
'smtp_pass' => 'J@kO()FF%u]I',
'mailtype' => 'html',
'starttls' => true,
'charset' => 'utf-8',
'wordwrap' => TRUE,
$config['newline'] = "\r\n",
$config['crlf'] = "\r\n"
);
$message = '';
$this->load->library('email', $config);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('test@demo.example.com');
$to_email = $this->input->post('email');
$this->email->to($to_email); // change it to yours
$mail_data = array(
'username' => $to_email,
'password' => random_string('alnum', 16)
);
$msg = $this->load->view('YMI/demo.php', $mail_data, true);
$this->email->subject('Subject');
$this->email->message($msg);
if ($this->email->send()) {
echo 'Email sent.';
} else {
show_error($this->email->print_debugger());
}
$this->load->view('YMI/admin/custEmail');
}
答案 0 :(得分:0)
添加标题将帮助设置电子邮件的所需格式。 另外,如果您在现场加载视图,是否可以按预期完全加载?
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');