简体   繁体   中英

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. Also I'm getting an error with whole html code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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