ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Sending HTML mail in codeignitor

October 29, 2010 2:28am

Subscribe [6]
  • #1 / Oct 29, 2010 2:28am

    shankar ganesh

    18 posts

    I am new to codeignitor, i try to send HTML content in email, but received mail contains the source code as below what exactly in view page. How to solve this problem?

    <html>
      <body>
          <form name=“email_form” method=“post”>
            <b>This is test mail from Codeignitor with attachment and html format, please ignore it..<b>
          </form>
      </body>
    </html>

    Below is my controller code

    <?php
    class Send_mail extends Controller
    {
    function Send_mail()
    {
    parent::Controller();
    $this->load->library("email");
    }
      function index()
      {

    $this->email->from("[email protected]","Shankar Ganesh.N");
    $this->email->to("[email protected]");

    $this->email->subject("Test mail from codeignitor");
    $mesg=$this->load->view('emails',"",true);

    $this->email->message($mesg);

    $config['mailtype'] = 'html';
    $config['charset'] = 'utf-8';
    $config['newline'] = "\r\n";

    $this->load->library('email', $config);

    $data['message']=$this->email->send()?'Message was sent successfully!':'Error sending email!';

    echo "<br><br><br>";
    echo $this->email->print_debugger();

    }
    }
    ?>


    Below is my view code

    <html>
      <body>
          <form name=“email_form” method=“post”>
            <b>This is test mail from Codeignitor with attachment and html format, please ignore it..<b>
          </form>
      </body>
    </html>

  • #2 / Oct 29, 2010 3:27am

    mi6crazyheart

    333 posts

    Where is u’r these following preferences…

    $this->email->clear();            
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'fill up this according to your settings';
    $config['smtp_user'] = 'fill up this according to your setting';
    $config['smtp_pass'] = 'fill up this according to your setting';
    $config['charset'] = 'iso-8859-1';

    One more thing u’r not sending any data to that VIEW file…

    $mesg=$this->load->view(‘emails’,”“,true);

    It should be some like this…

    $msg = $this->load->view('emails_view',$data_about_emailMsg, true);
    $this->email->message($msg);
  • #3 / Oct 29, 2010 3:56am

    shankar ganesh

    18 posts

    I am using mail protocol,

    Below is send_mail.php for controller

    function index()
        {
            $this->email->clear();       
            $this->email->from("[email protected]","Shankar Ganesh.N");
            $this->email->to("[email protected]");
    
            $this->email->subject("Test mail from codeignitor");
            $data['content']="This is test mail from Codeignitor with attachment and html format, please ignore it..";
            $mesg=$this->load->view('emails',$data,true);
    
            $this->email->message($mesg);
    
            $config['protocol'] = 'mail';
            $config['charset'] = 'iso-8859-1';  
            $config['mailtype'] = 'html';
            $config['newline'] = "\r\n";
    
            $this->load->library('email', $config);  
    
            $data['message']=$this->email->send()?'Message was sent successfully!':'Error sending email!';
            
            echo "<br><br><br>";
            echo $this->email->print_debugger();
    
        }


    Below is email.php for views

    <html>
        <body>
            <form name="email_form" method="post">
                <b><?=$content;?><b>
            </form>
        </body>
    </html>


    but still i face the problem

  • #4 / Oct 29, 2010 5:02am

    mi6crazyheart

    333 posts

    Just got one error. Don’t it’s just a printing mistake or some else…
    When you are loading u’r VIEW file u r using name “emails”...

    $mesg=$this->load->view('emails',$data,true);

    But, in u’r view file name is “email.php” . If i’m right plz correct it & reply back…

  • #5 / Oct 29, 2010 5:50am

    shankar ganesh

    18 posts

    Sorry! the view’s file name is emails.php i sentenced as email.php

  • #6 / Oct 29, 2010 9:41am

    mi6crazyheart

    333 posts

    Hey, with u’r current settings/preferences can u able to send TEXT mail rather than HTML mail… ?

  • #7 / Oct 31, 2010 11:45pm

    shankar ganesh

    18 posts

    I can able to send plain text also with attachment, but not HTML..

  • #8 / Nov 01, 2010 12:56am

    mi6crazyheart

    333 posts

    Are u getting any debugging result… ?

    echo $this->email->print_debugger();
  • #9 / Nov 01, 2010 1:03am

    shankar ganesh

    18 posts

    I got like below,

    Your message has been successfully sent using the following protocol: mail
    
    From: "Shankar Ganesh.N" 
    Return-Path: 
    Reply-To: "[email protected]" 
    X-Sender: .(JavaScript must be enabled to view this email address)
    X-Mailer: CodeIgniter
    X-Priority: 3 (Normal)
    Message-ID: <[email protected]>
    Mime-Version: 1.0
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: 8bit
    =?utf-8?Q?Test_mail_from_codeignitor?=
    <html>
        <body>
                This is test mail from Codeignitor with attachment and html format,
    please ignore it..    </body>
    </html>
  • #10 / Mar 22, 2011 12:29pm

    satanuzo

    3 posts

    Yo tengo el mismo problema

    codeigniter envia
    Content-Type: text/plain; charset=utf-8

    y deberia ser:
    Content-Type: text/html; charset=utf-8

  • #11 / Nov 29, 2011 5:10pm

    jtrainaldi

    24 posts

    I am experiencing a weird issue with sending HTML emails to Outlook clients and was wondering if anyone else is experiencing issues with this and knows of any solutions (other than don’t use Outlook).


    Manually defined email preferences

    $config['mailtype'] = 'html';
    $config['charset'] = 'utf-8';


    Below is the HTML that is being sent using the CI email function.

    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>XYZ Intranet</title>
    </head>
    <body>
    <h2>Teacher Walkthrough Has Been Published For Your Viewing Pleasure</h2>
    <p>Please click the link below to view your teacher walkthrough.<br />
    <a href="http://intranet.xyz.org/walkthrough/view/25"> Teacher Walkthrough </a><br />
    </body><br />
    </html>

    This is the source code that my Outlook client shows.

    <html lang="en">
    <head>
    <title> Intranet</title=
    </head>
    <body>
    <h2>Teacher Walkthrough Has Been Published For Your Viewing P=easure</h2>
    <p>Please click the link below to view your teacher walkthrough=.<br />
    <a href="http://intranet.xyz.org/walkthrough/view/25"> Teacher W=lkthrough </a><br />
    </body><br />
    </html>

    Notice how equal signs are inserted into the source code.  The weird thing is that this doesn’t happen on Gmail or Yahoo.

    When codeigniter packages everything for the send() function the Content-Type: text/html; charset=utf-8 seems to wrap the content and add an equal sign for the line return. 

    User-Agent: CodeIgniter
    Date: Wed, 30 Nov 2011 13:16:23 -0600
    From: "Intranet Notification" 
    Return-Path: 
    Reply-To: "[email protected]" 
    X-Sender: .(JavaScript must be enabled to view this email address)
    X-Mailer: CodeIgniter
    X-Priority: 3 (Normal)
    Message-ID: <[email protected]>
    Mime-Version: 1.0
    Content-Type: multipart/alternative; boundary="B_ALT_4ed68107dc072"
    
    
    =?utf-8?Q?Your_Teacher_Walkthrough_Has_Been_Published?=
    This is a multi-part message in MIME format.
    Your email application may not support this format.
    
    --B_ALT_4ed68107dc072
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: 8bit
    
    Teacher Walkthrough Has Been Published For Your Viewing PleasurePlease click
    the link below to view your teacher walkthrough. Teacher Walkthrough
    
    
    --B_ALT_4ed68107dc072
    Content-Type: text/html; charset=utf-8
    Content-Transfer-Encoding: quoted-printable
    
    <html lang=3D"en"><head><meta charset=3D"utf-8"><title>Intranet</title=
    ></head><body><h2>Teacher Walkthrough Has Been Published For Your Viewing P=
    leasure</h2>Please click the link below to view your teacher walkthrough=
    .
    <a > Teacher W=
    alkthrough </a></body></html>
    
    --B_ALT_4ed68107dc072--

     

  • #12 / Nov 30, 2011 2:37pm

    jtrainaldi

    24 posts

    Error Fixed by adding the following preferences:

    $config[‘crlf’] = “\r\n”;
    $config[‘newline’] = “\r\n”;

  • #13 / Dec 01, 2011 1:25pm

    jimmykak

    12 posts

    Wow That was definitely a hard one. I was actually having some of the same issues. Glad to know someone out there has the answers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases