?
Solved

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

Posted on 2008-09-29
6
Medium Priority
?
281 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 2000 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

800 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