php mail function - received message does not look right on Exchange, but looks fine on Apache

Hello Experts!

I am using the PHP mail() function to sumbit a form from the website to the client email.  The email looks perfect on a Linux mailbox, but received by an Exchange mailbox, I don't see the correct FROM information, and I can see all the html tags inside the email. I am pasting my code below.

Looking forward to your suggestions!!

$message1 = stripslashes("
 <title>Communication from website</title>
<table border='0' cellpadding='1' cellspacing='1'>
<tr align='left'><td colspan='2'><font size='+1'><b>Contact Us form from website</b></font><br><br></td></tr>
<tr><td align='right' class='gray12' valign='top'>First Name:&nbsp;</td><td>$first_name</td></tr>
<tr><td align='right' class='gray12' valign='top'>Last Name:&nbsp;</td><td>$last_name</td></tr>
<tr><td align='right' class='gray12' valign='top'>Company:&nbsp;</td><td>$Company</td></tr>
<tr><td align='right' class='gray12' valign='top'>Street Address:&nbsp;</td><td>$Street</td></tr>
<tr><td align='right' class='gray12' valign='top'>State:&nbsp;</td><td>$state0</td></tr>
<tr><td align='right' class='gray12' valign='top'>Zipcode:&nbsp;</td><td>$zipcode $plusfour</td></tr>
<tr><td align='right' class='gray12' valign='top'>Email:&nbsp;</td><td>$zipcode $email</td></tr>
<tr><td align='right' class='gray12' valign='top'>Phone:&nbsp;</td><td>$phone</td></tr>
<tr><td align='right' class='gray12' valign='top'>Interested:&nbsp;</td><td>$Interested</td></tr>
<tr><td align='right' class='gray12' valign='top'>Comments:&nbsp;</td><td>$comments</td></tr>

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

$headers .='From: '.$fname. ' '.$lname.'<'.$email.'>' . "\r\n";
$subj='Contact Us form from website';
//$from = "From: \"$fname $lname\" <$email>\nX-Mailer: PHP/" . phpversion;
mail('', $subj, $message1, $headers);
Who is Participating?
bansidharConnect With a Mentor Commented:
try changing
$headers .='From: '.$fname. ' '.$lname.'<'.$email.'>' . "\r\n";
$headers .='From: "'.$fname. ' '.$lname.'" <'.$email.'>' . "\r\n";

I cannot see any other problems. If this won't work please post the full mail header received by mail client. I can try to figure out the problem
why are you stripping the slashes, your html code seems to be having no extra slashes to be stripped.

try using

message1 = "your html";
instead of
message1 = stripslashes("your html");
bscnyAuthor Commented:
That didn't help. It shouldn't be the problem. I stripped slashes in case there are slashes in the submitted form.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

bscnyAuthor Commented:
Hi bansidhar,

Didn't work still. I am about ready to give up. Outlook web access doesn't support showing headers, and since unfortunately I don't have control of this particular exchange server, I don't think I can get the headers out. I emailed the administrator; will have to see if he is able to get me the headers for the message.

Is it a common workaround to just strip out the html and settle for a plain text message?
can you post the headers received by your mail client? I can try to figure out what is wrong from the standard header.
why cant you try PHPmailer ( it can handle maile much more efficiently and less coding issues.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.