简体   繁体   English

图像和CSS未加载到Codeigniter电子邮件中

[英]Images and css are not loading in codeigniter email

I'm sending an html view in email.Email has been sent successfully but after receiving an email images are not not loading and css are not applying. 我正在通过电子邮件发送html视图。电子邮件已成功发送,但是在接收到电子邮件后图像未加载且CSS未应用。 Also I'm getting an error with whole html code. 另外,我在整个HTML代码中遇到了错误。

Error 错误

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');
}

Adding Headers will help set the required format for your email. 添加标题将帮助设置电子邮件的所需格式。 Also if you load your view on site does it fully load as expected? 另外,如果您在现场加载视图,是否可以按预期完全加载?

 $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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM