Welcome Guest, Not a member yet? Register   Sign In
html email still sending as text/plain
#1

[eluser]doubleplusgood[/eluser]
Hi there,

I have a controller that sends an email. But the email received always comes through as Content-Type: text/plain; charset=utf-8, even though I have the controller and config set to send html email as follows;

Code:
$this->load->library('email');
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";

$this->email->initialize($config);

Anyone else had this problem? :S
#2

[eluser]umefarooq[/eluser]
try to debug you email with $this->email->print_debugger() and check config you are setting proper or not
#3

[eluser]umefarooq[/eluser]
try to debug you email with $this->email->print_debugger() and check config you are setting proper or not
#4

[eluser]Dennis Rasmussen[/eluser]
What does $this->email->print_debugger() say?

edit: umefarooq beat me to it Smile
#5

[eluser]doubleplusgood[/eluser]
Debugger isn't actually showing me anything. Sad
#6

[eluser]LuckyFella73[/eluser]
Can you post more of your code? At least all the lines about
sending the mail. It's strange that your call to
Code:
$this->email->print_debugger()
doesn't output anything.

Maybe the order of your lines messed up by accident?
Here what I had in a project a while ago:
Code:
$this->load->library('email');

$config['wordwrap'] = FALSE;
$this->email->initialize($config);

$this->email->from('[email protected]', 'Me');
$this->email->to('[email protected]');

$this->email->subject('subject');
$this->email->message('message');

$this->email->send();
        
echo $this->email->print_debugger();
I didn' set encoding to utf-8 but the debugging worked ...
#7

[eluser]techgnome[/eluser]
From the UG: "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."

So my next question would be... what are you setting as the message body of the email?

-tg
#8

[eluser]InsiteFX[/eluser]
Some mail systems have trouble with utf-8

Try changing the charset to iso-8859-1 and see if it works.

InsiteFX
#9

[eluser]doubleplusgood[/eluser]
Hey guys,

So here is the code from my send function;

Code:
function send()
    {        
        // field name, error message, validation rules
        $this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
        $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email|xss_clean');
        $this->form_validation->set_rules('telephone', 'Telephone Number', 'trim|xss_clean');
        $this->form_validation->set_rules('enquiry', 'Enquiry', 'trim|required|xss_clean');*/
        
        
        // validation has passed. Now send the email
        $name = $this->input->post('name', TRUE);
        $email = $this->input->post('email', TRUE);
        $telephone = $this->input->post('telephone', TRUE);
        $bike = $this->input->post('bike', TRUE);
        $enquiremethod = $this->input->post('enquiremethod', TRUE);
        $description = $this->input->post('description', TRUE);
        $our_price = $this->input->post('our_price', TRUE);
        $list_price = $this->input->post('list_price', TRUE);
        $url_slug = $this->input->post('url_slug', TRUE);
        $url = strtolower($url_slug);
        $formattedprice = substr($our_price,0,-3);
        $formattedlistprice = substr($list_price,0,-3);
        $saving = $formattedlistprice - $formattedprice;
        
        $data=array(
        'name'=>$name,
        'email'=>$email,
        'telephone'=>$telephone,
        'bike'=>$bike,
        'enquiremethod'=>$enquiremethod,
        'our_price'=>$our_price,
        'list_price'=>$list_price,
        'url_slug'=>$url_slug,
        'created'=>date('Y-m-d h:i:s'),
        'updated'=>date('Y-m-d h:i:s')
        );
        $this->load->model('quoteenquiremodel');
        $this->quoteenquiremodel->insert($data);
        
        $this->load->library('email');
        $config['mailtype'] = 'html';
        $config['charset'] = 'utf-8';
        $config['newline'] = "\r\n";

        $this->email->initialize($config);

        $this->email->from($this->config->item('website_from_email'), $this->config->item('website_from_email_name'));
        $this->email->reply_to($email, $name);
        $this->email->bcc($this->config->item('email_to'));
        $this->email->to($email);
        
        if($enquiremethod == 'quote') {
            $this->email->subject('QUOTE REQUEST');    
            $message = "Hi $name,<br />
<br />
The current list price on this bike is £$formattedlistprice OTR.<br />
<br />
We are currently able to offer this bike at an astonishing: <strong>£$formattedprice OTR</strong>.<br />
<br />
An amazing saving of: <strong>£$saving</strong>.<br />
<br />
This price is only available whilst current stocks last.<br />
<br />
$description<br />
Kind Regards<br />
Sales Team";
        //} elseif($enquirymethod == 'enquiry') {
        } else {
            $this->email->subject('ENQUIRY');    
            $message = "Details of your enquiry:-<br />
<br />
Bike: $bike<br />
<br />
Bike description: $description<br />
<br />
User Name: $name<br />
User Email: $email<br />
User Telephone: $telephone<br />
<br />
Kind Regards;
        }
        
            
        $this->email->message($message);
        
        if($this->email->send())
        {
            if($enquiremethod == 'quote') {
                $formattedprice = substr($our_price,0,-3);
                $phpsubject = "Bike Quote";
                $phpemailto = "$telephone";
                $smsmessage = "Our best price on the $bike is £$formattedprice OTR.";
                
                mail($phpemailto,$phpsubject,$smsmessage);
            }
            return true;
        }

        else
        {
            show_error($this->email->print_debugger());
        }

    }

}
#10

[eluser]LuckyFella73[/eluser]
Hi Hanabi,

I found some small errors - just check if your script works now:
Code:
&lt;?php
function send()
{        
    // field name, error message, validation rules
    $this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
    $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email|xss_clean');
    $this->form_validation->set_rules('telephone', 'Telephone Number', 'trim|xss_clean');
    $this->form_validation->set_rules('enquiry', 'Enquiry', 'trim|required|xss_clean');
    
    
    // validation has passed. Now send the email
    $name = $this->input->post('name', TRUE);
    $email = $this->input->post('email', TRUE);
    $telephone = $this->input->post('telephone', TRUE);
    $bike = $this->input->post('bike', TRUE);
    $enquiremethod = $this->input->post('enquiremethod', TRUE);
    $description = $this->input->post('description', TRUE);
    $our_price = $this->input->post('our_price', TRUE);
    $list_price = $this->input->post('list_price', TRUE);
    $url_slug = $this->input->post('url_slug', TRUE);
    $url = strtolower($url_slug);
    $formattedprice = substr($our_price,0,-3);
    $formattedlistprice = substr($list_price,0,-3);
    $saving = $formattedlistprice - $formattedprice;
    
    $data = array(
        'name'=>$name,
        'email'=>$email,
        'telephone'=>$telephone,
        'bike'=>$bike,
        'enquiremethod'=>$enquiremethod,
        'our_price'=>$our_price,
        'list_price'=>$list_price,
        'url_slug'=>$url_slug,
        'created'=>date('Y-m-d h:i:s'),
        'updated'=>date('Y-m-d h:i:s')
    );
    $this->load->model('quoteenquiremodel');
    $this->quoteenquiremodel->insert($data);
    
    $this->load->library('email');
    $config['mailtype'] = 'html';
    $config['charset'] = 'utf-8';
    $config['newline'] = "\r\n";

    $this->email->initialize($config);

    $this->email->from($this->config->item('website_from_email'), $this->config->item('website_from_email_name'));
    $this->email->reply_to($email, $name);
    $this->email->bcc($this->config->item('email_to'));
    $this->email->to($email);
    
    if($enquiremethod == 'quote')
    {
        $this->email->subject('QUOTE REQUEST');
        $message = "
            Hi $name,<br /><br />
            The current list price on this bike is £$formattedlistprice OTR.<br /><br />
            We are currently able to offer this bike at an astonishing: <strong>£$formattedprice OTR</strong>.<br /><br />
            An amazing saving of: <strong>£$saving</strong>.<br /><br />
            This price is only available whilst current stocks last.<br /><br />
            $description<br />
            Kind Regards<br />
            Sales Team
        ";
    //} elseif($enquirymethod == 'enquiry') {
    }
    else
    {
        $this->email->subject('ENQUIRY');
        $message = "
            Details of your enquiry:-<br /><br />
            Bike: $bike<br /><br />
            Bike description: $description<br /><br />
            User Name: $name<br />
            User Email: $email<br />
            User Telephone: $telephone<br /><br />
            Kind Regards
        ";
    }
    
        
    $this->email->message($message);
    
    if($this->email->send())
    {
        echo $this->email->print_debugger();
        /* makes no sense as far as I can see
           why send mail with PHP mail() when allready
           send via CI E-Mail Class ?
        if($enquiremethod == 'quote')
        {
            $formattedprice = substr($our_price,0,-3);
            $phpsubject = "Bike Quote";
            $phpemailto = "$telephone";
            $smsmessage = "Our best price on the $bike is £$formattedprice OTR.";
            
            mail($phpemailto,$phpsubject,$smsmessage);
        }
        */
        return true;
    }

    else
    {
        show_error($this->email->print_debugger());
    }
}
?&gt;

Good luck Wink




Theme © iAndrew 2016 - Forum software by © MyBB