Welcome Guest, Not a member yet? Register   Sign In
html emails using email class
#21

[eluser]rossmurphy[/eluser]
And here are my email settings in application/config/email.php

Code:
$config['useragent']    = "CodeIgniter";
$config['mailpath']        = "/usr/sbin/sendmail";    // Sendmail path
$config['protocol']        = "mail";                // mail/sendmail/smtp
$config['smtp_host']    = "";                    // SMTP Server.  Example: mail.earthlink.net
$config['smtp_user']    = "";                    // SMTP Username
$config['smtp_pass']    = "";                    // SMTP Password
$config['smtp_port']    = "25";                    // SMTP Port
$config['smtp_timeout']    = 5;                    // SMTP Timeout in seconds
$config['wordwrap']        = TRUE;                    // TRUE/FALSE  Turns word-wrap on/off
$config['wrapchars']    = "76";                    // Number of characters to wrap at.
$config['mailtype']        = "html";            // text/html  Defines email formatting
$config['charset']        = "utf-8";                // Default char set: iso-8859-1 or us-ascii
$config['multipart']    = "mixed";                // "mixed" (in the body) or "related" (separate)
$config['alt_message']    = '';                    // Alternative message for HTML emails
$config['validate']        = FALSE;                // TRUE/FALSE.  Enables email validation
$config['priority']        = "3";                    // Default priority (1 - 5)
$config['newline']        = "\n";                    // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
$config['crlf']            = "\n";                    // The RFC 2045 compliant CRLF for quoted-printable is "\r\n".  Apparently some servers,
                                                // even on the receiving end think they need to muck with CRLFs, so using "\n", while
                                                // distasteful, is the only thing that seems to work for all environments.
#22

[eluser]rossmurphy[/eluser]
Ok so i used a new installation of codeigniter to test this. Here is my code:

Code:
<?php

class Emailtest extends Controller {

    function Emailtest()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->library('parser');
        $this->load->library('email');
        
        $config['mailtype'] = 'html';

        $this->email->initialize($config);
        
        $this->email->from('[email protected]', 'Support name');
        $this->email->to('[email protected]');

        $this->email->subject('Email Test');
        
        $message = '<html>';
        $message .= '<head>';
        $message .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
        $message .= '<title>{site_name} | Forgot Password Notification</title>';
        $message .= '</head>';
        $message .= '<body style="background-color:#f7f7f7;">';
        $message .= '<div style="border:5px solid #ffffff; width:642px; background-color:#ffffff;">';
        $message .= '<div style="height:16px; padding:6px 4px 4px 8px; color:#016599; font-family:Arial, Sans-serif; width:630px; font-size:11px; font-weight:bold; background-color:#e3f4f8;">';
        $message .= '{site_name} | Forgot Password Notification';
        $message .= '</div>';
        $message .= '<div style="border:1px solid #e3f4f8; background-color:#ffffff; padding:20px; font-family:Arial, Sans-serif; font-size:13px; width:600px;">';
        $message .= '<p style="padding:0; margin:0;">';
        $message .= '<span style="font-size:19px;">Dear, {alias}!</span>';
        $message .= '<br /><br />';
        $message .= 'You recently went through the password recovery process at {site_name}. The recovery was successful.';
        $message .= '<br /><br />';
        $message .= '<div style="width:98%; height:23px; padding:8px 0 4px 2%; background-color:#f6f6f6; border:1px solid #eeeeee; border-width:1px 1px 4px 1px; margin:12px 0;">';
        $message .= '<span style="font-weight:bold;">Your password is:</span> {password}';
        $message .= '</div>';
        $message .= 'If you feel you are receiving this email in error, please contact {support_email}.';
        $message .= '<br /><br />';
        $message .= '<div style="width:98%; height:23px; padding:8px 0 4px 2%; background-color:#f6f6f6; border-top:1px solid #eeeeee; border-bottom:1px solid #eeeeee; margin:12px 0;">';
        $message .= '<a style="text-decoration:none;" href="{egift_link}">Click here</a> to go to the login page.<br />';
        $message .= '</div>';
        $message .= '<br /><br />';
        $message .= 'All the best,';
        $message .= '<br /><br />';
        $message .= '<span style="font-weight:bold;">{site_name} Team.</span>';
        $message .= '</p>';
        $message .= '</div>';
        $message .= '</div>';
        $message .= '&lt;/body&gt;';
        $message .= '&lt;/html&gt;';
        
        $this->email->message($message);

        $this->email->send();

        echo $this->email->print_debugger();
    }
}

This is what i am still getting:

Quote:{site= _name} | Forgot Password Notification
Dear, {alias}!

You recently went= through the password recovery process at {site_name}. The recovery was suc= cessful.



Your password= is: {password}
If you feel you are receiving this email in err= or, please contact {support_email}.


Click here to go to the log= in page.



All the best,

{site_name} Team.

--B_ALT_4b4f95c18bd9d--
#23

[eluser]JHackamack[/eluser]
Well your single quotes are preventing the variables from being replaced, so thats one problem.
#24

[eluser]rossmurphy[/eluser]
I'm not using the parser here so don't worry about that.
#25

[eluser]JHackamack[/eluser]
Downloaded a fresh CI install Copied your code (except put it in the welcome controller as i was too lazy) And received the HTML Email using the Apple Mail Program.
All I changed was the config.php file to point to localhost
Welcome.php
Code:
&lt;?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->library('parser');
        $this->load->library('email');
        
        $config['mailtype'] = 'html';

        $this->email->initialize($config);
        
        $this->email->from('[email protected]', 'Support name');
        $this->email->to('Hidden for Anonimity');

        $this->email->subject('Email Test');
        $message = '&lt;html&gt;';
...snip for length...
        $message .= '&lt;/html&gt;';
        $this->email->message($message);

        $this->email->send();

        echo $this->email->print_debugger();
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
Debugger
Code:
User-Agent: CodeIgniter
Date: Thu, 14 Jan 2010 17:34:36 -0800
From: "Support name"
Return-Path:
Reply-To: "[email protected]"
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_4b4fc62cf352b"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_4b4fc62cf352b
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

{site_name} | Forgot Password NotificationDear, {alias}!You recently went
through the password recovery process at {site_name}. The recovery was
successful.Your password is: {password}If you feel you are receiving this
email in error, please contact {support_email}.Click here to go to the login
page.All the best,{site_name} Team.


--B_ALT_4b4fc62cf352b
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
=?utf-8?Q?Email_Test?=
&lt;html&gt;&lt;head>&lt;meta http-equiv=3D"Content-Type" content=3D"text/html; charset=
=3Dutf-8" /&gt;&lt;title>{site_name} | Forgot Password Notification&lt;/title&gt;&lt;/head=
>&lt;body style=3D"background-color:#f7f7f7;"&gt;&lt;div style=3D"border:5px solid #=
ffffff; width:642px; background-color:#ffffff;"><div style=3D"height:16px; =
padding:6px 4px 4px 8px; color:#016599; font-family:Arial, Sans-serif; widt=
h:630px; font-size:11px; font-weight:bold; background-color:#e3f4f8;">{site=
_name} | Forgot Password Notification</div><div style=3D"border:1px solid #=
e3f4f8; background-color:#ffffff; padding:20px; font-family:Arial, Sans-ser=
if; font-size:13px; width:600px;"><p style=3D"padding:0; margin:0;"><span s=
tyle=3D"font-size:19px;">Dear, {alias}!</span><br /><br />You recently went=
through the password recovery process at {site_name}. The recovery was suc=
cessful.<br /><br /><div style=3D"width:98%; height:23px; padding:8px 0 4px=
2%; background-color:#f6f6f6; border:1px solid #eeeeee; border-width:1px 1=
px 4px 1px; margin:12px 0;"><span style=3D"font-weight:bold;">Your password=
is:</span> {password}</div>If you feel you are receiving this email in err=
or, please contact {support_email}.<br /><br /><div style=3D"width:98%; hei=
ght:23px; padding:8px 0 4px 2%; background-color:#f6f6f6; border-top:1px so=
lid #eeeeee; border-bottom:1px solid #eeeeee; margin:12px 0;"><a >Click here</a> to go to the log=
in page.<br /></div><br /><br />All the best,<br /><br /><span style=3D"fon=
t-weight:bold;">{site_name} Team.</span></p></div></div>&lt;/body&gt;&lt;/html>

--B_ALT_4b4fc62cf352b--
#26

[eluser]WebsiteDuck[/eluser]
This has to do with your lines being over 76 characters long, and the content-transfer-encoding being quoted-printable.

Even in JHackamack's debug the equal signs are present, but his email client is stripping them out.

Seems like an e-mail client issue. Maybe it's confused as to why you would use 8bit encoding for your text/plain part, and 7bit encoding for your text/html part Tongue (not you personally, but codeigniter)
#27

[eluser]rossmurphy[/eluser]
Thanks for your help. Can anyone point me to a CI tutorial for sending HTML email? I cannot get a single HTML email to send properly. But in 1.7.1 i had no problem.

I tried to change the miltipart setting to related and in the debugger i saw the correct email but in my email it was blank.
#28

[eluser]JHackamack[/eluser]
Double check your email connection settings. Make sure your host supports either php's native mailer or sendmail. If you want a tutorial you can use my above example as a good starting point, as it successfully works.
#29

[eluser]WebsiteDuck[/eluser]
This won't help you with codeigniter's library, but you might use it for testing:

Code:
$to = "[email protected]";

$header = "From: John Doe <[email protected]>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
  
$message = "<p>This <b>is</b> <i>an</i> <u>html</u><br />\n";
$message .= "email! </p><br /> <hr />";
    
mail($to, 'subject', $message, $header);
#30

[eluser]codepotato[/eluser]
Hi,

I think i've solved this problem here :

http://ellislab.com/forums/viewthread/69463/#811241




Theme © iAndrew 2016 - Forum software by © MyBB