Magento Forum

   
Page 1 of 2
HTML Transactional Email not working on all clients
 
aFox
Jr. Member
 
Total Posts:  15
Joined:  2008-09-02
 

Hello,

my customer’s shop is almost ready, and the only thing still wrong is that I can’t get the transactional emails to work in HTML-format. Well, basically they work in the desktop clients, but some webmail clients, like Horde and SquirrelMail refuse to render the HTML. They just show the markup. I’ve checked out all the settings and found nothing.

I’ve checked the headers and they seem ok. Content-Type is set to html and character encoding is utf-8.

Comparison with Amazon’s emails indicate that Amazon has the Content-Type as multipart/alternative and of course plain text alternative as the multipart expects. But shouldn’t the Content-Type html also make an html attachment of the html email?

I would use plain text, but I can’t get the billing information and order items to render in plain text. The email placeholders just give out HTML markup.

So how can I make sure that every html-client(even Horde and SquirrelMail) renders the email at least somehow. My email template is very simple.
Or how can I get the plain text version to print out just plain text. No HTML at all!

Thank you!

 
Magento Community Magento Community
Magento Community
Magento Community
 
oshipper
Member
 
Total Posts:  53
Joined:  2008-02-04
New York, NY
 

Did you have any luck solving this? I have the same issue when trying to do plain text order confirmations.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
aFox
Jr. Member
 
Total Posts:  15
Joined:  2008-09-02
 

Nope, nothing yet. I haven’t found this in the issue queues either, so maybe I should file an issue for this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
aFox
Jr. Member
 
Total Posts:  15
Joined:  2008-09-02
 

TEMPORARY SOLUTION!!

I created a temporary solution to this problem, which enables the system to send email in multipart/alternative content-type. This way, the customers’ mail client can choose from html vs. plain text version. This solution has been tested with Magento 1.2.0.3 and using mail clients Horde, SquirrelMail, OpenCube and Mail.app.

This solution involves hacking a core file, so it’s not pretty and not recommended if you don’t know what you’re doing.

STEP 1) Hack the core file app/code/core/Mage/Core/Model/Email/Template.php

Starting from line 345, change the following code:

if($this->isPlain()) {
    $mail
->setBodyText($text);
else {
    $mail
->setBodyHTML($text);
}

into this:

$boundary '--BOUNDARY_TEXT_OF_CHOICE';
$stext substr($text0strpos($text$boundary));
$shtml str_replace($boundary''substr($textstrpos($text$boundary)));

$mail->setBodyText($stext);
$mail->setBodyHTML($shtml);

STEP 2) Modify the transactional email templates.
Your email templates must be of type HTML. Then, FIRST write you PLAIN TEXT version into the body, write your boundary text where you want it to end and then put your HTML -version after the boundary.

Example:

Hello{{var customer.name}}

--BOUNDARY_TEXT_OF_CHOICE

<style>span{display:blockbackground-coloryellow;}</style>
<
span>Hello, <strong>{{var customer.name}}</strong></span>

Previously, the code has checked if the email template is plain text or HTML and then sets the email body to either one. Now, the modified code sets the preferred boundary line, separates the plain text and html -versions and embeds them to the email. Zend mail automatically adds the multipart/alternative -meta tags.

How to make this better??
Well… it would be better if the system would automatically pick up both plain text and HTML versions from separate templates by using the template title (or ID, if you know how to do it). Also, my PHP is not the prettiest. Please improve if you know better!

 
Magento Community Magento Community
Magento Community
Magento Community
 
isotrope
Jr. Member
 
Total Posts:  14
Joined:  2008-10-28
 

Awesome!

Thank you so much, aFox. Can’t wait to try it out. Will post back once I do.
Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paul R Burton
Jr. Member
 
Total Posts:  25
Joined:  2008-12-02
 

I’m having the same issue with a store I just launched and it only took one sale, the very first sale, to bring this ridiculous issue to the attention of my client.

Would it be too much to ask for someone who has implemented this solution to post the complete templates as samples? 

The snippet provided here is a little vague, or perhaps I am a little vague.

Thanks,
P

 
Magento Community Magento Community
Magento Community
Magento Community
 
oshipper
Member
 
Total Posts:  53
Joined:  2008-02-04
New York, NY
 

Nice work aFox. May I asked if you solved the sections of transactional emails that only output in html format? Like
here:  {{var items_html}}

That was the part that was always getting me. Have not found a text output for this so have just cleaned up the html as best I could in hopes a solution would eventually present itself.

Speaking of which anyone try out the Enhanced Email Extension - http://www.magentocommerce.com/extension/802/artsonit-enhanced-mail. Very pricey and not alot of details or feedback from users…

Best,
A

 
Magento Community Magento Community
Magento Community
Magento Community
 
erenaud
Sr. Member
 
Total Posts:  221
Joined:  2009-01-05
Minden, Germany
 

I tested the artsonit extension by going to their demo site. you can enter your mail address and will receive a sample email.
I used Horde to display it and it was indeed text version. In another client I saw the html version.
really not to bad, but as you said, there are no user ratings or comments or whatsoever.

Also too bad that one would have to buy that extension - this should be core functionality of magento.

 
Magento Community Magento Community
Magento Community
Magento Community
 
oshipper
Member
 
Total Posts:  53
Joined:  2008-02-04
New York, NY
 

I just reviewed artsonit email demo site and the email it sent to a test gmail account did not display images as promised. It worked correctly in Eudora which is a definite improvement for Magento Size came in at 130k though and not sure if that was the just the images used or the text/html. Will investigate more.

As far as being core functionality, this is one of those things that is there to convince you you need to hire a “professional”. Totally intentional that email does not work correctly.

 
Magento Community Magento Community
Magento Community
Magento Community
 
erenaud
Sr. Member
 
Total Posts:  221
Joined:  2009-01-05
Minden, Germany
 

I bought the artsonitextension.

negative:
- after I paid the script via paypal, I was informed that the script would be sent to me via email.
It took them 48 hours to send it to me.

- the php script is protected with ioncube technology (php scrambler) which required additional
attention.

until now I did not finish installing it due to the ioncube technology.

positive:
... will let you know once I installed it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
erenaud
Sr. Member
 
Total Posts:  221
Joined:  2009-01-05
Minden, Germany
 

I have the artsonit extension installed now.

it works great for us: in horde the plain text (extracted from html) is shown, in outlook the logo image is embedded.

I can only recommend it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
botc
Member
 
Total Posts:  43
Joined:  2009-05-16
 

Hi aFox,

Thanks for help. I have however some problems, I hope you can help me with.

I have done as you said about chaning the template.php and add’ed the plain text before anything else in my html emails.

This is what the top of my new-account html looks like:

<!--@subject Velkommen{{var customer.name}}! @-->

Hej{{var customer.name}}

bla bla text
... 

E-mail{{var customer.email}}<br/>
Password{{var customer.password}}<p>

--
BOUNDARY_TEXT_OF_CHOICE

<style type="text/css">

body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }

</style>.........

This gives how ever a blank page in squirrelmail - and the added html version is also blank.

If I send out that mail without the plain text version, I get a blank page in squirrelmail - but the html version vorks.

Can anyone see what goes wrong here?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ph23man
Jr. Member
 
Total Posts:  14
Joined:  2007-08-31
 

Thank you aFox for posting this solution!

HTML-only emails are also more likely to be flagged as spam (SpamAssassin, Gmail, etc.) so I think this is a major problem.

I changed up aFox’s code slightly - if you haven’t modified all of your email templates, the HTML-only ones will be handled as they were before.

With aFox’s original code, it’ll pass a blank $stext if you the boundary text isn’t in your template. This should be relatively harmless, but the OCD in me doesn’t want to pass it at all if it’s blank. Basically the revision below will only do the plain-text/HTML combo magic if the boundary text is found in your template. Otherwise, it reverts to the original behavior.

This was tested on Magento 1.3.1.

STEP 1) Hack the core file app/code/core/Mage/Core/Model/Email/Template.php

Starting from line 345, change the following code:

if($this->isPlain()) {
    $mail
->setBodyText($text);
else {
    $mail
->setBodyHTML($text);
}

into this:

$boundary '--BOUNDARY_TEXT_OF_CHOICE';
$boundary_location strpos($text$boundary);
if (
$boundary_location{
    $stext 
substr($text0strpos($text$boundary));
    
$shtml str_replace($boundary''substr($text$boundary_location));
    
$mail->setBodyText($stext);
    
$mail->setBodyHTML($shtml);         
else {
    
if($this->isPlain()) {
        $mail
->setBodyText($text);
    
else {
        $mail
->setBodyHTML($text);
    
}
}

STEP 2) Modify the transactional email templates.
Your email templates must be of type HTML. Then, FIRST write you PLAIN TEXT version into the body, write your boundary text where you want it to end and then put your HTML -version after the boundary.

 
Magento Community Magento Community
Magento Community
Magento Community
 
botc
Member
 
Total Posts:  43
Joined:  2009-05-16
 

Thanks! It’s now working :D The last hurdle before going online smile

.. I just can’t show the items than the costumer has order in plain text. the {{items_html}} - is there a solution for that?

Thanks again smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
botc
Member
 
Total Posts:  43
Joined:  2009-05-16
 

I have found a new problem! :(

It seems like this only works on sales-emails I can edit in backoffice, my emails for e.g. a new account are empty. (All mail I have to edit from folder app\locale\da_DK\template\email doesn’t work.

How do you set up these html files?

Should the <!--@subject Welcome, {{var customer.name}}! @--> come first, or after the --BOUNDARY_TEXT_OF_CHOICE ?

I have tried so many times, all turned out as a blank email. Also no html-version is added to the mail, so all customer will notice this!

Thank you so much for help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
loeffel
Guru
 
Avatar
Total Posts:  427
Joined:  2009-02-03
 

It seems like this only works on sales-emails I can edit in backoffice, my emails for e.g. a new account are empty. (All mail I have to edit from folder app\locale\da_DK\template\email doesn’t work.

Maybe I am not getting something here, but cant you just load these templates in Transactional Emails in the Backend?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2