PHP Mail - Some people are recieving html code

Hello,

I have the below code and on my Apple Mail program I receive the nice layout of the email but on other apps such as Outlook they see html code.

Can you please let me know if I have my headers wrong.

	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	$headers .= 'From: website Autos Online Inquiry <info@website-autos.com>' . "\r\n";
	$headers .= 'BCC: website Autos <info@website-autos.com>' . "\r\n";
	$headers .= 'Reply-to: '.$name.' <'.$email.'>' . "\r\n";
	$subject='website Autos Online Inquiry';

$body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        
        <meta property="og:title" content="website Autos Vehicle Inquiry" />
        
        <title>website Autos Vehicle Inquiry</title>
	<style type="text/css">
			#outlook a{padding:0;} /* Force Outlook to provide a "view in browser" button. */
			body{width:100% !important;} .ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */
			body{-webkit-text-size-adjust:none;} /* Prevent Webkit platforms from changing default text sizes. */
			body{margin:0; padding:0;}
			img{border:0; height:auto; line-height:100%; outline:none; text-decoration:none;}
			table td{border-collapse:collapse;}
			#backgroundTable{height:100% !important; margin:0; padding:0; width:100% !important;}
			body, #backgroundTable{
				/*@editable*/ background-color:#222222;
				background-image: url(http://www.website-autos.com/img/haBack-1.jpg);
				background-repeat: repeat;
			}
			#templateContainer{
			}
			h1, .h1{
				/*@editable*/ color:#202020;
				display:block;
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:34px;
				/*@editable*/ font-weight:bold;
				/*@editable*/ line-height:100%;
				margin-top:0;
				margin-right:0;
				margin-bottom:10px;
				margin-left:0;
				/*@editable*/ text-align:left;
			}
			h2, .h2{
				/*@editable*/ color:#202020;
				display:block;
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:30px;
				/*@editable*/ font-weight:bold;
				/*@editable*/ line-height:100%;
				margin-top:0;
				margin-right:0;
				margin-bottom:10px;
				margin-left:0;
				/*@editable*/ text-align:left;
			}
			h3, .h3{
				/*@editable*/ color:#FFFFFF;
				display:block;
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:26px;
				/*@editable*/ font-weight:bold;
				/*@editable*/ line-height:100%;
				margin-top:0;
				margin-right:0;
				margin-bottom:10px;
				margin-left:0;
				/*@editable*/ text-align:left;
			}
			h4, .h4{
				/*@editable*/ color:#202020;
				display:block;
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:18px;
				/*@editable*/ font-weight:bold;
				/*@editable*/ line-height:100%;
				margin-top:0;
				margin-right:0;
				margin-bottom:10px;
				margin-left:0;
				/*@editable*/ text-align:left;
			}
			#templatePreheader{
			}
			.preheaderContent div{
				/*@editable*/ color:#505050;
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:10px;
				/*@editable*/ line-height:100%;
				/*@editable*/ text-align:left;
			}
			.preheaderContent div a:link, .preheaderContent div a:visited, /* Yahoo! Mail Override */ .preheaderContent div a .yshortcuts /* Yahoo! Mail Override */{
				/*@editable*/ color:#336699;
				/*@editable*/ font-weight:normal;
				/*@editable*/ text-decoration:underline;
			}
			#templateHeader{
				/*@editable*/ border-bottom:0;
			}
			.headerContent{
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:34px;
				/*@editable*/ font-weight:bold;
				/*@editable*/ line-height:100%;
				/*@editable*/ padding:0;
				/*@editable*/ text-align:center;
				/*@editable*/ vertical-align:middle;
			}
			.headerContent a:link, .headerContent a:visited, /* Yahoo! Mail Override */ .headerContent a .yshortcuts /* Yahoo! Mail Override */{
				/*@editable*/ color:#336699;
				/*@editable*/ font-weight:normal;
				/*@editable*/ text-decoration:underline;
			}
			#headerImage{
				height:auto;
				max-width:600px !important;
			}
			.bodyContent{
				background-color:#FFF;
				background-image: url(http://www.website-autos.com/img/h600.png);
				background-repeat: repeat-x;
				background-position: left top;
			}
			.bodyContent div{
				/*@editable*/ color:#505050;
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:14px;
				/*@editable*/ line-height:150%;
				/*@editable*/ text-align:left;
				padding:10px 20px;
			}
			.bodyContent div a:link, .bodyContent div a:visited, /* Yahoo! Mail Override */ .bodyContent div a .yshortcuts /* Yahoo! Mail Override */{
				/*@editable*/ color:#336699;
				/*@editable*/ font-weight:normal;
				/*@editable*/ text-decoration:underline;
			}
			.bodyContent img{
				display:inline;
				height:auto;
			}
			#templateFooter{
				/*@editable*/ border-top:0;
			}
			.footerContent div{
				/*@editable*/ color:#707070;
				/*@editable*/ font-family:Arial;
				/*@editable*/ font-size:12px;
				/*@editable*/ line-height:125%;
				/*@editable*/ text-align:left;
			}
			.footerContent div a:link, .footerContent div a:visited, /* Yahoo! Mail Override */ .footerContent div a .yshortcuts /* Yahoo! Mail Override */{
				/*@editable*/ color:#336699;
				/*@editable*/ font-weight:normal;
				/*@editable*/ text-decoration:underline;
			}
			.footerContent img{
				display:inline;
			}
			#social{
				/*@editable*/ border:0;
			}
			#social div{
				/*@editable*/ text-align:center;
			}
			#utility{
				/*@editable*/ border:0;
			}
			#utility div{
				/*@editable*/ text-align:center;
			}

			#monkeyRewards img{
				max-width:190px;
			}
		</style>
</head>
    <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
    	<center>
        	<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="backgroundTable">
            	<tr>
                	<td align="center" valign="top">
                    	<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateContainer">
                        	<tr>
                            	<td align="center" valign="top">
                                    <!-- // Begin Template Header \\ -->
                                	<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateHeader">
                                        <tr>
                                            <td class="headerContent">
                                            
                                            	<!-- // Begin Module: Standard Header Image \\ -->
                                            	<img src="http://www.website-autos.com/img/website-header-logo-email.png" width="600" height="148" alt="website Autos Logo" />
                                            	<!-- // End Module: Standard Header Image \\ -->
                                            
                                            </td>
                                        </tr>
                                    </table>
                                    <!-- // End Template Header \\ -->
                                </td>
                            </tr>
                        	<tr>
                            	<td align="center" valign="top">
                                    <!-- // Begin Template Body \\ -->
                                	<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateBody">
                                    	<tr>
                                            <td valign="top" class="bodyContent">
                                                <!-- // Begin Module: Standard Content \\ -->
                                                <table border="0" cellpadding="20" cellspacing="0" width="100%">
                                                    <tr>
                                                        <td valign="top">
                                                            <div mc:edit="std_content00">
                                                                <h4 class="h4">Vehicle Inquiry - '.$row['year'].' '.$row['make'].' '.$row['model'].'</h4>
																<strong>From:</strong> '.$name.'
                                                                <br />
                                                                <strong>Phone Number:</strong> '.$phone.'
                                                                <br />
                                                                <strong>Email Address:</strong> '.$email.'
                                                                <br />
                                                                <strong>Message:</strong><br />
                                                                '.nl2br($message).'<br /><br />
                                                                <strong>Link to vehicle:</strong> <a href="http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"].'">Click Here</a><br />
                                                            </div>
														</td>
                                                    </tr>
                                                </table>
                                                <!-- // End Module: Standard Content \\ -->
                                            </td>
                                        </tr>
                                    </table>
                                    <!-- // End Template Body \\ -->
                                </td>
                            </tr>
                        	<tr>
                            	<td align="center" valign="top">
                                    <!-- // Begin Template Footer \\ -->
                                	<table border="0" cellpadding="10" cellspacing="0" width="600" id="templateFooter">
                                    	<tr>
                                        	<td valign="top" class="footerContent">
                                            
                                                <!-- // Begin Module: Standard Footer \\ -->
                                                <table border="0" cellpadding="10" cellspacing="0" width="100%">
                                                    <tr>
                                                        <td colspan="2" valign="middle" id="social">
                                                            <div mc:edit="std_social">
                                                                <a href="http://www.website-autos.com/website_autos_login.php">Manage Inventory</a> | <a href="http://www.facebook.com/websiteAutos">Like website Autos on Facebook</a>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="2" valign="middle" id="utility">
                                                            <div mc:edit="std_utility">
                                                                &copy; website Autos | website-autos.com
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                                <!-- // End Module: Standard Footer \\ -->
                                            </td>
                                        </tr>
                                    </table>
                                    <!-- // End Template Footer \\ -->
                                </td>
                            </tr>
                        </table>
                        <br />
                    </td>
                </tr>
            </table>
        </center>
    </body>
</html>';

	// Fix any bare linefeeds in the message to make it RFC821 Compliant.
	$body = preg_replace("#(?<!\r)\n#si", "\r\n", $body);
	   
	// Make sure there are no bare linefeeds in the headers
	$headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers); 
	
	mail($to, $subject, $body, $headers);

Open in new window

LVL 1
movieprodwAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

haloexpertsexchangeCommented:
Those headers look fine, they are the same as I have used before.
It is possible that outlook is set up to read emails as plain text instead of html.
0
Loganathan NatarajanLAMP DeveloperCommented:
Otherwise, try to convert this simple mail script to phpmailer class way. so that it will  take care these issues.

http://phpmailer.worxware.com/index.php?pg=examplebmail
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
liveaspankajCommented:
i generally keep the html in a separate file, so that i can test the html and even validate it.

1. So make a file like email.html with pure html page and sample text content (no php here)
2. Test/Varify/Validate the html
3. Replace the sample text content with tags like {HEAD}, {MESSAGE}, etc
4. instead of $body = "html code .....";
use

$body = file_get_contents("/path/to/email.html");
//Replace the tages
$body = str_replace("{MESSAGE}", $message, $body);
$body = str_replace("{HEAD}", $head, $body);
//everything that you need to...

Now you can be sure that you have a good code, unless your $message etc variables contents bad code, or markup.
0
liveaspankajCommented:
That will also help you maintain seperate email templates :)
0
movieprodwAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.