Form mail encoding

Permalink
Hello!
When receiving the mail that notify me a form submission I get a human unreadable BASE64 encoded text.
I've tested to send a simple mail with phpmail and it arrives correctly.
I report a mail that came from my Concrete5 site:
Content-type: text/plain; charset=UTF-8
From: <!!MY_REMOVED_E-MAIL_ADDRESS!!>
Mime-Version: 1.0
Content-Transfer-Encoding: BASE64
CkUnIHN0YXRvIGludmlhdG8gaWwgZm9ybSBSaWNoaWVzdGEgaW5mb3JtYXppb25pIHRyYW1pdGUg
aWwgdHVvIHNpdG8gQ29uY3JldGU1LgoKRW1haWwgcGVyc29uYWxlDQpoZW5yaWsuc296em
ETC, ETC, ETC (I've removed the other base64 lines)


The simple script I've successfully used to test phpmail was this:
<?php
error_reporting(E_ALL);
$mail_from="postmaster@!!MY_REMOVED_DOMAIN!!";
$mail_subject="Testing e-mail";
$mail_text="Questa è una e-Mail di test inviata dal servizio Hosting di Aruba.it per la verifica del corretto funzionamento di PHP mail()function .
Aruba.it";
$mail_to="!!MY_REMOVED_E-MAIL!!";
if( mail( $mail_to, $mail_subject, $mail_text, "From: {$mail_from}\r\n" ) ) {
    echo "Mail inviata correttamente !<br><br>Questo di seguito è il codice sorgente usato per l'invio della mail:<br><br>";
    highlight_file($_SERVER["SCRIPT_FILENAME"]);
    unlink($_SERVER["SCRIPT_FILENAME"]);
} else
    echo "<br><br>Recapito e-Mail fallito!";
?>


Can anyone give me an advice on how to fix this?
Thank you,
Henrik

energywave
 
energywave replied on at Permalink Reply
energywave
Are you sure you don't know about this issue? Should I disable the mail notify? Is it not working?
Xscratch replied on at Permalink Reply
Xscratch
I am experiencing this issue right now.
With v5.2.x everything was fine.
I also tried disabling the localization file.
Maynar replied on at Permalink Reply
Maynar
Yeah got that here to now and notified the IT department here. What his problem seemed to be was that the main email server doesn't know BASE64 decoding, he rerouted it to the INTRANET server and that works. Temporary solution tho...
kutis replied on at Permalink Reply
kutis
simple example
$mh = Loader::helper('mail');
$mh->to('destination@email.com');
$mh->from('from@email.com', 'from name');
$mh->setSubject('the subject');
$mh->setBody("line one\nline two");
@$mh->send();


ps: that's from memory, double check the api to be sure
Jim replied on at Permalink Reply
I am having the same problem: with outlook 2007 i get a mix of characters, but reading it on my mobile phone it shows up correctly.

Is it a problem of outlook or the way it is sent?

I cant fint any settings for sending email in concrete, or is there?

Hope to fix this asap!!!
Thanks for any help
energywave replied on at Permalink Reply
energywave
I debugged the incriminated file: mail.php in concrete/helpers directory and SOLVED the problem!
I've found it by analyzing the raw content of the mail that I've got (following a small piece for understanding):
Subject: Richiesta informazioni Conferma form
MIME-Version: 1.0
Content-type: text/plain; charset=UTF-8
From: ************ (my mail)
Mime-Version: 1.0
Content-Transfer-Encoding: BASE64


Now we know that in SMTP protocol two consecutive CRLF determine the begin of the mail body.
The problem is around "Content-type: text/plain; charset=UTF-8", watching in hex i've found that sequence: "0d 0d 0a".

That means that after "MIME-Version: 1.0" the real mail started, resulting in loosing the following headers lines (that you could see in the body...)

So i changed the line 122 and 123 of mail.php removing "\r" leaving only new line "\n", so the resulting of those two lines is the following:
$header  = "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=" . APP_CHARSET . "\n";


Now I have only "0D 0A" and it works fine!

While watching I've found another bug... at line 129 there is:
if (function_exists('mb_encode_mimeheade')) {


...but there is a typo at the end of the string, it should be 'mb_encode_mimeheader'.

I've informed the admin about that so that it can be fixed in the next release.
katz515 replied on at Permalink Reply
katz515
if (function_exist ('mb_encode_mimeheade')) {

This maybe why the mail has been converted to BASE64

Also... in addition to your misspell fix, sometime... you may have to set the php.ini to be like this

PHP.INI Setting

default_charset = UTF-8
mbstring.language = neutral
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = UTF-8

or

.htaccess
php_value mbstring.language neutral
php_value mbstring.internal_encoding UTF-8
php_value mbstring.http_input auto
php_value mbstring.http_output UTF-8


This is how I solved my mail encoding for Japanese.

But thank you for finding the mispell~!
energywave replied on at Permalink Reply
energywave
Hm, that maybe can fix the encoding (I'm a real newbie of php), but the double CR? Does it work for you? Don't you receive a mail with a body that begin as the following?
Content-type: text/plain; charset=UTF-8
From: <mail inserted in form>
Mime-Version: 1.0
Content-Transfer-Encoding: BASE64
<the form content>

Plus it comes from an anonymous user...
If you fix the header it comes from the mail that the user inserted in form and no wrong header at the beginning of the form.
Can you check how are your mails?
katz515 replied on at Permalink Reply
katz515
Here is my mail header
From: XXXXXX@concrete5-japan.org
Date: May 11, 2009 5:43:45 PM PDT
To: XXXXXXX@concrete5-japan.org
Mime-Version: 1.0
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: BASE64


And I'm using Gmail & Apple Mail. And it's working fine without modifying the mail.php misspell.
energywave replied on at Permalink Reply
energywave
However the body is still encoded in BASE64 and you have too "Mime-Version: 1.0" twice (I didn't mention that but me too).
I'll test your solution to see the effects returning to standard mail.php.
However the problem, I believe, was not the mispelling, but the "\r\n" that becomed "\n".
Can you check if you have "0D 0D 0A" or "0D 0A" before and after "Contet-type: text/plain; charset=UTF-8"?
katz515 replied on at Permalink Reply
katz515
Yeah...

For me, it's working fine... so I let "Mime-Version: 1.0" to repeat.

And I decided to carry on my life to the next level :p

But yeah... we may want to fix this.

Sorry.. I have a presentation tomorrow... I'll catch this up later.
energywave replied on at Permalink Reply
energywave
Ok, ok, it's true, who cares about that :) My goal was to receive a readable mail and to help bugfixing Concrete5 ;)
Good luck for your presentation!
katz515 replied on at Permalink Reply
katz515
So it was good that they misspelled "mb_encode_mimeheader".

I learned that "mb_encode_mimeheader" should only be used if there is no mb_send.

So if you are sending mbstring via regular mail or send_mail, you need to do mb_encode_mimeheader for mail subject.

But mb_send alaready does its job.

There is nothing to do with your topic... but thanks to your finding.... it got my attention. Thanks energywave!
Jim replied on at Permalink Reply
That solved it for me too.

Thanks energywave!
cwheelsone replied on at Permalink Reply
I got that 'gibberish' also. Taking off they '\r' worked. I tried the .htaccess method, but that did'nt make any differance for me. I use Thunderbird for my pop mail.
cwheelsone replied on at Permalink Reply
Where does one make additional tweaks like 'Reply to', the body text etc ... "There has been a submission of..."?
gregdorrian replied on at Permalink Reply
gregdorrian
Hi i'm being playing around ALL morning trying to fix this. Thank you it works now:-)!