Discussion:
does your mail() base64 encode messages?
John W. List
2005-03-18 12:32:14 UTC
Permalink
I have an unexpected and perplexing problem.
PHP's mail() function is base64 encoding all message bodies as an
ill-formed MIME attachment resulting in the recipient seeing an
uninteligable base64 encoded string. This only happens to my account
with my host and neither I or the sysadmin can see why as there are no
special configuration settings for me. The host is running PHP4.3.10.

Here's what is happening:
This code
<?php
mail ( "***@myhost.tld", "test script", "Foo!", "");
?>

Results in this mail being recieved.

(message starts here)
Delivered-To: ***@myhost.tld

<snip all the SMTP Recieved: headers for clarity/>

To: ***@myhost.tld
Subject: test script
Message-Id: <***@mail.myhost.tld>
Date: Fri, 18 Mar 2005 10:33:06 +0000 (GMT)
From: ***@myhost.tld (httpd)

Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: BASE64

Rm9vIQ==
(message ends here)

On every other PHP host I've used I would have expected a simple
string "Foo!" instead of the Mime-version stuff and the base64 encoded
string.

I'm sure I can get round this if I have to by using one of the PHP
mail classes that are out there. But I'd prefer not to as one of the
pieces of software I'm using is commercial and if I alter it I'll
invalidate my support for it.
Has anyone else seen this problem? I'd be interested to know what's happening.
John W. List
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Burhan Khalid
2005-03-19 08:27:05 UTC
Permalink
Post by John W. List
I have an unexpected and perplexing problem.
PHP's mail() function is base64 encoding all message bodies as an
ill-formed MIME attachment resulting in the recipient seeing an
uninteligable base64 encoded string. This only happens to my account
with my host and neither I or the sysadmin can see why as there are no
special configuration settings for me. The host is running PHP4.3.10.
This code
<?php
Try mail("***@myhost.tld","test script","Foo!");

Don't send empty headers -- it might be causing the problem. Fwiw, I
have never encountered this issue.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
John W. List
2005-03-19 12:08:50 UTC
Permalink
Thanks very much for your suggestion- It did not fix the problem but
it provided a pointer to a workaround.

It appears that my host base64 encodes message bodies if any sort of
header- even an empty one- is supplied. This is a problem the sysadmin
is looking into but for now I have to live with it.

The empty header caused mail() to put a \n in between the headers and
the MIME headers for the base64 encoded stuff. This in turn caused
mail readers to view the message as a plain text message that happened
to contain a base64 encoded string so the recipient saw gibberish.
Removing the empty header resulted in a plain text message, putting a
valid header in the headers parameter caused the mail to be viewed by
the mail reader as a normal base64 encoded message and thus readable
by the recipient. Unfortunately mail()'s habit of doing this base64
encoding precludes me from doing anything with MIME multipart messages
because all the multipart separators, HTML etc become visible as plain
text, but at least I can send emails containing plain text.

And so to the commercial application which originally showed up this
problem. Its mail code had an extra \n at the end of its headers.
Removing this made it possible for it to send plain text emails,
albeit base64 encoded ones, from this host. I've used this application
from quite a few other customers hosts in the past so this \n is not
normally a problem, but I've never used a host that exhibits this
behaviour. As well as removing this \n I had to comment out the lines
that sent multipart emails but at least now I'm in business.

As to the problem itself, I'm none the wiser. As I see it it can only
be either PHP or Sendmail that is doing this. I've never had this or
any other version of PHP do this to me before but since as I
understand it Sendmail is only being used as a mail relay here I cant
place the blame anywhere else but a possible bug in PHP 4.3.10's
mail() function. It's not a bug, it's a feature!:)

I guess it's all extra experience.
John W. List
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...