Solved

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

Posted on 2008-09-29
6
277 Views
Last Modified: 2009-10-15
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!!

<?php
$message1 = stripslashes("
<html>
<head>
 <title>Communication from website</title>
</head>
<body>                  
<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>
</table>
</body>
</html>
");

$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('test@bscny.com', $subj, $message1, $headers);
?>
0
Comment
Question by:bscny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:bansidhar
ID: 22598326
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");
0
 

Author Comment

by:bscny
ID: 22598774
That didn't help. It shouldn't be the problem. I stripped slashes in case there are slashes in the submitted form.
0
 
LVL 11

Accepted Solution

by:
bansidhar earned 500 total points
ID: 22603214
try changing
$headers .='From: '.$fname. ' '.$lname.'<'.$email.'>' . "\r\n";
to
$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
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:bscny
ID: 22662180
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?
0
 
LVL 11

Expert Comment

by:bansidhar
ID: 22666336
can you post the headers received by your mail client? I can try to figure out what is wrong from the standard header.
0
 
LVL 11

Expert Comment

by:bansidhar
ID: 22666343
why cant you try PHPmailer (http://phpmailer.codeworxtech.com/) it can handle maile much more efficiently and less coding issues.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question