Solved

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

Posted on 2008-09-29
6
271 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
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:bansidhar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:bscny
Comment Utility
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
Comment Utility
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
Comment Utility
why cant you try PHPmailer (http://phpmailer.codeworxtech.com/) it can handle maile much more efficiently and less coding issues.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
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 …

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now