CodeIgniter Forums

Full Version: What is wrong with the Codeigniter Email Class?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Timothy_[/eluser]
Hello fellow code-igniters,

I am in the last stages of programming the first release of some software I have been writing over the last 8 months.

This involves adding the 30 or so different emails that will be triggered from the application.

I have got to say that although I love codeigniter, the email class has really let me down

1. No matter what I specify in the email config file it always outputs plain text. Not only that but it appears the config arrays were wrong in the default file that came with the latest version of CI
Code:
$config['email']['mailtype']  = 'html';
which after reading http://ellislab.com/forums/viewthread/89514/ I changed to
Code:
$config['mailtype'] = 'html';
2. Still not working... So i took another suggestion from that same thread and initialised the config directly under the load library call in my controller
Code:
$email_config['mailtype'] = 'html';

$this->email->initialize($email_config);
3. Finally!!! the debugger says that the content type went out as html... but
4. I check my gmail and I can't find the html email I just sent. I open up the spam folder and there it is. Despite all efforts it is always sending the CI html emails straight to spam but the normal plain texts ones make it through.

Where do I go from here. One helpful person on one of the countless threads I looked at suggested using the plugin PHPmailer. I really want to avoid this. My app is huge and I am trying to avoid excessive loading of external plugins that will slow the app down and probably wont be supported in the future.

I really hope I personally am doing something wrong and that yet again CI will pleasantly surprise me.

Tim

El Forum

[eluser]tonanbarbarian[/eluser]
just because gmail has marked the message as spam does not mean it is not being sent as html
the reasons that gmail marks something as spam and varied
if you can move the message oout of the spam and the n look at it, is it in html?
try viewing the source, which in gmail is called Show Original.
does the header contain the following (or similar)
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Is the content source html?

If so then your email is producing HTML correctly and gmail is marking it as spam for another reason, i.e. the content of the message may be something suspicious such as a very short html message with no subject
try sending to other email accounts that are not in gmail and see if the message comes through as html
do not worry about html formatting to begin with just confirm the email is received as html and work on formatting later

El Forum

[eluser]Timothy_[/eluser]
Hello,

The source of the email seems to be both...

Can you make sense of it?

Code:
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_4ce08533ed522"

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

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

HelloHow are you


--B_ALT_4ce08533ed522
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
&lt;html&gt;&lt;head>&lt;META http-equiv=3D"Content-Type" content=3D"text/html; charset=
=3Dutf-8"&gt;&lt;/head>&lt;body&gt;&lt;p>Hello<br/>How are you</p>&lt;/body&gt;&lt;/html>

--B_ALT_4ce08533ed522--

Thanks,

Tim

El Forum

[eluser]tonanbarbarian[/eluser]
that is normal.
CI attempts to create a text only version of the email if you send HTML, so that if your email client does not support HTML, or you have HMTL display disabled, you can still see something. This is good practice.

So as I said previously the message is sending HTML fine. The reason it is marked as spam in Gmail is likely to do with the content, or perhaps the domain you have sent it from is considered a spam host by gmail, but if the text email got through without being marked spam then it is the content.

try again with some more realistic content in the email and it will probably come through fine.

El Forum

[eluser]Timothy_[/eluser]
Thanks,

You were right. I managed to get it out of spam by adding more realistic content. Thank-you!

Now the question remains... why do I have to initialise the config file in each controller? Why is it not global like the rest of the config files?

Code:
$email_config['mailtype'] = 'html';
$this->email->initialize($email_config);

Thanks,

Tim