Mail() suddenly sends html as attachments!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjsw
Forum Newbie
Posts: 10
Joined: Fri Jul 09, 2010 9:18 am

Mail() suddenly sends html as attachments!

Post by mjsw »

Hi,

I have a problem with mail function in php. I use it in such method:

function send_mail_html($rec, $subject, $body, $replyto)
{
if($replyto=="")
$replyto = load_variable('owner_email');

$result=mail($rec, $subject, $body,
"From: ".load_variable('owner_email')."\r\n"
."Reply-To: ".$replyto."\r\n"
."Return-Path: ".load_variable('owner_email')."\r\n"
."Content-Type: text/html\r\n"
."X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)");
}

this method has not changed in last 6 months and emails were sent fine with it, but suddenly yesterday the client can't receive html emailm normally - html content is received as an attachement by MS Outlook 2007. I must add that MS Outlook had some updates installed recently which most pobably cause that problem. Hosting staff told me that problem might be with header and "\r\n" line breaks, but I read in manual that it is made correctly.

I have to ask what can be wrong with my method? Does it miss something or is there anything obvously wrong? Is it possible that long html lines in message body cause it (over 70 chars)? or \r\n line endings instead of \n?

BTW I don't know what X-Mailer is for and why it is set to MS Outlook, I saw also PHP+phpversion() instead but I don't know the purpose of it as this script isn't my.

Any help will be appreciated!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Mail() suddenly sends html as attachments!

Post by Jonah Bron »

Try sending to a Gmail or Yahoo account to test. In Outlook, is there anything in the message body? Also, see if it helps to put all headers mentioned in the PHP manual

Code: Select all

$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mjsw
Forum Newbie
Posts: 10
Joined: Fri Jul 09, 2010 9:18 am

Re: Mail() suddenly sends html as attachments!

Post by mjsw »

Jonah Bron wrote:Try sending to a Gmail or Yahoo account to test. In Outlook, is there anything in the message body? Also, see if it helps to put all headers mentioned in the PHP manual

Code: Select all

$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
hi,

I have viewed this mail in webmail which provides online access to this account and everything is fine there. Problem is in Outlook and its recently installed updates, or to be more precise, problem is in the way outlook treat the messages send by php with the method I've shown. Something is wrong in headers or encoding, or I don't know what else...

Also, the problem happens only when sender and recipient are on the same server and domain, let say sender@domain.com sends to recipient@domain.com - there is the error. When I send to gmail, yahoo or any other server Outlook receives the message as it should - without attachments.

I will try your solution in coming minutes and will report back how it works...
Post Reply