Sending HTML Email results in Email displaying HTML source (Codeigniter Email Class)

how to send email in codeigniter from localhost demo
codeigniter send email without smtp
codeigniter send email->to multiple recipients
send email codeigniter - stack overflow
codeigniter email error
codeigniter send html email
codeigniter email library download
cannot send mail with no from'' header

I am having problems with email sent via the email class in Codeigniter displaying the source HTML code in the email message instead of the rendered HTML view. For testing, I am currently having CI on XAMPP on Windows, and using Gmail SMTP to send to the same gmail address.

The function that sends the email is as follows:

$config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'myaccountname@gmail.com',
        'smtp_pass' => 'mygmailpassword',
        );

    $this->load->library('email', $config); 
    $this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->to($email);
    $this->email->subject(sprintf($this->lang->line('auth_subject_'.$type), $this->config->item('website_name', 'tank_auth')));
    $this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));
    $this->email->set_alt_message($this->load->view('email/'.$type.'-txt', $data, TRUE));

    $this->email->set_newline("\r\n"); // require this, otherwise sending via gmail times out

    $this->email->send();

There is no problem getting the text version sent. The view loaded is a html file that will be emailed out.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Welcome to <?php echo $site_name; ?>!</title></head>
<body>
<div style="max-width: 800px; margin: 0; padding: 30px 0;">
<table width="80%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="5%"></td>
<td align="left" width="95%" style="font: 13px/18px Arial, Helvetica, sans-serif;">
<h2 style="font: normal 20px/23px Arial, Helvetica, sans-serif; margin: 0; padding: 0 0 18px; color: black;">Welcome to <?php echo $site_name; ?>!</h2>
Thanks for joining <?php echo $site_name; ?>. We listed your sign in details below, make sure you keep them safe.<br />
To verify your email address, please follow this link:<br />
<br />
<big style="font: 16px/18px Arial, Helvetica, sans-serif;"><b><a href="<?php echo site_url('/auth/activate/'.$user_id.'/'.$new_email_key); ?>" style="color: #3366cc;">Finish your registration...</a></b></big><br />
<br />
Link doesn't work? Copy the following link to your browser address bar:<br />
<nobr><a href="<?php echo site_url('/auth/activate/'.$user_id.'/'.$new_email_key); ?>" style="color: #3366cc;"><?php echo site_url('/auth/activate/'.$user_id.'/'.$new_email_key); ?></a></nobr><br />
<br />
Please verify your email within <?php echo $activation_period; ?> hours, otherwise your registration will become invalid and you will have to register again.<br />
<br />
<br />
<?php if (strlen($username) > 0) { ?>Your username: <?php echo $username; ?><br /><?php } ?>
Your email address: <?php echo $email; ?><br />
<?php if (isset($password)) { /* ?>Your password: <?php echo $password; ?><br /><?php */ } ?>
<br />
<br />
Have fun!<br />
The <?php echo $site_name; ?> Team
</td>
</tr>
</table>
</div>
</body>
</html>

Any ideas how to get HTML emails sent to be rendered instead of displaying its source code?

Try adding the mailtype to the config:

$config = Array(
    'mailtype' => 'html',
    ...etc...
);

See http://codeigniter.com/user_guide/libraries/email.html

Sending HTML Email results in Email displaying HTML source , Try adding the mailtype to the config: $config = Array( 'mailtype' => 'html', etc ); See http://codeigniter.com/user_guide/libraries/email.html. I am having problems with email sent via the email class in Codeigniter displaying the source HTML code in the email message instead of the rendered HTML view. For testing, I am currently having CI

Try this

$this->email->set_mailtype("html");

php, Try adding the mailtype to the config: $config = Array( 'mailtype' => 'html', etc ); See http://codeigniter.com/user_guide/libraries/email.html. Sending HTML Email results in Email displaying HTML source (Codeigniter Email Class) 2 years ago Views 478 Visit Post Reply I am having problems with email sent via the email class in Codeigniter displaying the source HTML code in the email message instead of the rendered HTML view.

Add these two lines after loading your codeigniter mail library

$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');

full configuration: https://stackoverflow.com/a/38740292/4376484

Email Class, Multiple Protocols: Mail, Sendmail, and SMTP; TLS and SSL Encryption for SMTP If you send HTML email you must send it as a complete web page. $from (​string) – “From” e-mail address; $name (string) – “From” display name data // to not be cleared - if that happens, printDebugger() would have // nothing to output. To send an email with HTML content, set a preference (mailtype) by passing an array of preference value (html) to the email initialize function. Here is an example code to send HTML email in CodeIgniter.

Append the line commented in the example below:

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html'; // Append This Line
$this->email->initialize($config);

Email Class, Multiple Protocols: Mail, Sendmail, and SMTP; TLS and SSL Encryption for SMTP If you send HTML email you must send it as a complete web page. $from (​string) – “From” e-mail address; $name (string) – “From” display name data // to not be cleared - if that happens, print_debugger() would have // nothing to output. Sending email in CodeIgniter is much easier. You also configure the preferences regarding email in CodeIgniter. CodeIgniter provides following features for sending emails −. Multiple Protocols − Mail, Sendmail, and SMTP. TLS and SSL Encryption for SMTP. Multiple recipients. CC and BCCs. HTML or Plaintext email.

Set $config['protocol'] = "sendmail";

has fixed that for me

Codeigniter sending blank emails when more then one email is sent , Multiple Protocols: Mail, Sendmail, and SMTP; TLS and SSL If you send HTML email you must send it as a complete web page. $replyto (string) – E-mail address for replies; $name (string) – Display name for the reply-to e-mail address if that happens, printDebugger() would have // nothing to output. Sending email is not only simple, but you can configure it on the fly or set your preferences in the app/Config/Email.php file. Here is a basic example demonstrating how you might send email:

Displaying html tags in the codeigniter mail [duplicate], php's mail() via sendmail This happens when sending the same email, running the same code first example, but the results are the same with emails sent in order. email and if i send the emails out as plain-text instead of HTML everything being sent ok, although it's still showing the second email as  This tutorial tackles on how to send email in CodeIgniter using SMTP. Email is an essential function of a certain application especially if you wanted a registration verification, password resets, etc using emails. This tutorial will teach you on how to use CodeIgniter Email Library.

Sending HTML mail in codeignitor, answer here: Codeigniter how to html template for emails 3 answers Sending HTML Email results in Email displaying HTML source (Codeigniter Email Class)  This post explains how to send email using HTML templates in Codeigniter, how to send mails using HTML content and using phpmailer and gmail. Now we learn how to send mails in Codeigniter.

CodeIgniter Email and HTML Table, Chat with fellow EECMS users in the 'Sending HTML mail in HTML content in email, but received mail contains the source code as </html>. Below is my controller code. <?php class Send_mail Are u getting any debugging result… shankarganesh@gmail.com X-Mailer: CodeIgniter X-Priority: 3  I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Comments
  • You can't have PHP in an email body. I am also not sure you need the <html> or <body> tags.
  • @Nik: The PHP is generating the HTML that is sent, it's not actually in the email body.
  • Isn't the second code segment the HTML in the email? There is PHP in there. Obviously the first code segment is the generation.
  • thanks for this, really extrange. Need to set twice? or inside the $this->load->library('email', $config); the $config it's not working. thanks again
  • Call to undefined method CI_Email::set_header()