Welcome Guest, Not a member yet? Register   Sign In
HTML email sending as Text - Help
#1

[eluser]joehopkins[/eluser]
Hi,

I'm sending an Email from localhost - everything works except the HTML is sent as text:

email.php

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['protocol'] = 'mail';
//$config['protocol'] = 'smtp';
$config['smtp_host'] = 'localhost';
$config['email_address'] = '[email protected]';
$config['email_name'] = 'Localhost test';
$config['mailtype'] = 'html';
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";

model

Code:
$message='<html>
                        <head>
                        <meta charset="utf-8" />
                        <title>CRM Username and Password</title>
                        <style type="text/css" media="screen">
                        body {
                        font-family: Verdana, Arial;
                        }
                        </style>
                        </head>
                        <body>
                        <p>Hello '.$forename.'</p>
                        <p>Your username and password to log into the CRM system is:</p>
                        <p>username: <strong>'.$email.'</strong><br />
                        password: <strong>'.$password.'</strong></p>
                        <p>To log in, go to '.base_url().'</p>
                        <p>You can change your password after you log in.</p>
                        &lt;/body&gt;
                        &lt;/html&gt;
                        ';
                        $txt_message = '
                        Hello '.$forename.'
                        Your username and password to log into the CRM system is:\n\n
                        username: '.$email.'\n
                        password: <strong>'.$password.'\n\n
                        To log in, go to '.base_url().'\n\n
                        You can change your password after you log in.
                        ';
                        $this->load->library('email');
                        $this->email->from('crm@localhost', 'AAA CRM Manager');
                        $this->email->to($email);

                        $this->email->subject('CRM Username and Password');
                        $this->email->message($message);
                        $this->email->set_alt_message($txt_message);

                        if ( ! $this->email->send())
                        {
                         // Generate error

                         return 'Error: user WAS added to database but there was a problem sending the confirmation email with login details.'.$this->email->print_debugger();
                        }
                        else
                        {
                         $this->Log_model->add_to_log('User ('.$email.') added.');
                         return 'New user added.'.$this->email->print_debugger();
                        }

Debug output

Code:
Your message has been successfully sent using the following protocol: mail

From: "AAA CRM Manager"
Return-Path:
Reply-To: "crm@localhost"
X-Sender: crm@localhost
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4e3c00f1d7114@localhost>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?CRM_Username_and_Password?=
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;title&gt;CRM Username and Password&lt;/title&gt;
&lt;style type="text/css" media="screen"&gt;
body {
font-family: Verdana, Arial;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
<p>Hello Joe</p>
<p>Your username and password to log into the CRM system is:</p>
<p>username: <strong>[email protected]</strong><br />
password: <strong>4z328i4h</strong></p>
<p>To log in, go to http://localhost/awo/www/</p>
<p>You can change your password after you log in.</p>
&lt;/body&gt;
&lt;/html&gt;

Notice the 'Content-Type: text/plain'. The email I receive is just the HTML code.

What am I doing wrong?

Many thanks.

Joe
#2

[eluser]troy_mccormick[/eluser]
I'm not sure if you just left it out or not, but did you initialize your config?

Code:
&lt;?php
$this->email->initialize($config);
#3

[eluser]Aken[/eluser]
Troy, if you set your email config variables in an email.php config file, you don't need to initialize it.

Try displaying the properties of $this->email after you've loaded the library to see if it's receiving the config values properly:

Code:
$this->load->library('email');
exit(print_r($this->email, true));

Also, this line of your Email debug output worries me, and may be affecting your results:
Code:
=?utf-8?Q?CRM_Username_and_Password?=
#4

[eluser]joehopkins[/eluser]
Thanks troy_mccormick

I've tried the

Code:
&lt;?php
$this->email->initialize($config);

But no difference.

I read this was unnecessary anyway as I've defined it in the CI config folder email.php file.

Thanks,

Joe
#5

[eluser]joehopkins[/eluser]
Thanks Aken,

Here's my output:

Code:
CI_Email Object
(
    [useragent] => CodeIgniter
    [mailpath] => /usr/sbin/sendmail
    [protocol] => mail
    [smtp_host] =>
    [smtp_user] =>
    [smtp_pass] =>
    [smtp_port] => 25
    [smtp_timeout] => 5
    [wordwrap] => 1
    [wrapchars] => 76
    [mailtype] => text
    [charset] => utf-8
    [multipart] => mixed
    [alt_message] =>
    [validate] =>
    [priority] => 3
    [newline] =>

    [crlf] =>

    [send_multipart] => 1
    [bcc_batch_mode] =>
    [bcc_batch_size] => 200
    [_safe_mode] =>
    [_subject] =>
    [_body] =>
    [_finalbody] =>
    [_alt_boundary] =>
    [_atc_boundary] =>
    [_header_str] =>
    [_smtp_connect] =>
    [_encoding] => 8bit
    [_IP] =>
    [_smtp_auth] =>
    [_replyto_flag] =>
    [_debug_msg] => Array
        (
        )

    [_recipients] => Array
        (
        )

    [_cc_array] => Array
        (
        )

    [_bcc_array] => Array
        (
        )

    [_headers] => Array
        (
        )

    [_attach_name] => Array
        (
        )

    [_attach_type] => Array
        (
        )

    [_attach_disp] => Array
        (
        )

    [_protocols] => Array
        (
            [0] => mail
            [1] => sendmail
            [2] => smtp
        )

    [_base_charsets] => Array
        (
            [0] => us-ascii
            [1] => iso-2022-
        )

    [_bit_depths] => Array
        (
            [0] => 7bit
            [1] => 8bit
        )

    [_priorities] => Array
        (
            [0] => 1 (Highest)
            [1] => 2 (High)
            [2] => 3 (Normal)
            [3] => 4 (Low)
            [4] => 5 (Lowest)
        )

)

I notice the mailtype says 'text'. It's like the default isn't getting overridden.

Thanks again,

Joe
#6

[eluser]joehopkins[/eluser]
Bump...

I'm still having no joy overriding the email config. Can anyone think as to why?

Many thanks,

Joe
#7

[eluser]fornyhucker[/eluser]
User Guide says:
If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.

Check is your HTML code valid. May be it will help.
#8

[eluser]joehopkins[/eluser]
Thanks forneyhucker,

My HTML code is valid and there are no relative links or image paths. I've tried sending the HTML email as a view but exactly the same result. It seems that the config just won't get overridden.

Thanks,

Joe




Theme © iAndrew 2016 - Forum software by © MyBB