Mail returned sent via PHP - header problem - wrong format

catonthecouchproductions
catonthecouchproductions used Ask the Experts™
on
I have the code below, but it is getting trapped in my spam and showing as returned mail, is it my headers that are in the wrong format?

Ryan
<?php
error_reporting(E_ALL);
if(isset($_POST["honeypot"])){
	$honeypot = $_POST["honeypot"];
}

if(empty($honeypot)){
	//Check to make sure that the name field is not empty
	if(trim($_POST['date']) == '') {
		$hasError = true;
	} else {
		$date = trim($_POST['date']);
	}

	//Check to make sure that the name field is not empty
	if(trim($_POST['time']) == '') {
		$hasError = true;
	} else {
		$time = trim($_POST['time']);
	}
	if(trim($_POST['server']) == '') {
		$hasError = true;
	} else {
		$server = trim($_POST['server']);
	}
	if(trim($_POST['new_burger']) == '') {
		$hasError = true;
	} else {
		$new_burger = trim($_POST['new_burger']);
	}
	if(trim($_POST['rate_burger']) == '') {
		$hasError = true;
	} else {
		$rate_burger = trim($_POST['rate_burger']);
	}
	//Check to make sure comments were entered
	if(trim($_POST['burger_comments']) == '') {
		$hasError = true;
	} else {
		if(function_exists('stripslashes')) {
			$burger_comments = stripslashes(trim($_POST['burger_comments']));
		} else {
			$burger_comments = trim($_POST['burger_comments']);
		}
	}

	//If there is no error, send the email
	if(!isset($hasError)) {
		$emailTo = 'glanceatx@gmail.com'; //Put your own email address here

			$message  = '<html><body>';
			$message .= '<h2>Burger Survey - Customer Review</h2>';
			$message .= '<h3>Server: '.$server.'</h3>';
			$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
			$message .= "<tr><td><strong>Ate on:</strong> </td><td>" .$date. "</td></tr>";
			$message .= "<tr><td><strong>Time:</strong> </td><td>" .$time. "</td></tr>";
			$message .= "<tr><td><strong>Which Burger:</strong> </td><td>" .$new_burger. "</td></tr>";
			$message .= "<tr><td><strong>Burger Rating:</strong> </td><td>" .$rate_burger. "</td></tr>";
			$message .= "<tr><td><strong>Burger Comments:</strong> </td><td>" .$burger_comments. "</td></tr>";
			$message .= "</table>";
			$message .= "</body></html>";

		$headers  = 'From: Burger Survey @ Stars Hingham <burgersurvey@starsstarshingham.com>' . "\r\n Reply-To: burgersurvey@starsstarshingham.com \r\n";
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
		$subject  = "New Burger Survey Complete - Stars Hingham";
		mail($emailTo, $subject, $message, $headers, "-f $emailTo") or die("Mail error occurred");
		$emailSent = true;
	}
}else{
	echo "spam spam.";
}
?>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Are you sure that your MTA server is not blocking it due to a "masking" issue.  You can sometime choose to trust e-mails sent by localhost.

Additionally, is the name reporting correctly on your server and is that name resolving correctly to that server through DNS.  Sometimes the spam filter does not like to see messages sent from "mail@localhost"

HTH - flub
This is a copy of what I get:

The original message was received at Fri, 2 Jul 2010 08:10:07 -0700
from localhost [127.0.0.1]

  ----- The following addresses had permanent fatal errors -----
<glanceatx@gmail.com>
   (reason: 553 sorry, your mail was administratively denied. (#5.7.1))

  ----- Transcript of session follows -----
... while talking to relay-hosting.secureserver.net.:
>>> MAIL From:<glanceatx@gmail.com> SIZE=1425
<<< 553 sorry, your mail was administratively denied. (#5.7.1)
501 5.6.0 Data format error

Final-Recipient: RFC822; glanceatx@gmail.com
Action: failed
Status: 5.1.3
Diagnostic-Code: SMTP; 553 sorry, your mail was administratively denied. (#5.7.1)
Last-Attempt-Date: Fri, 2 Jul 2010 08:10:07 -0700


---------- Forwarded message ----------
From: "Burger Survey @ Stars Hingham <burgersurvey@starshingham.com> Reply-To": burgersurvey@starshingham.com
To: glanceatx@gmail.com
Date: Fri, 2 Jul 2010 08:10:07 -0700
Subject: New Burger Survey Complete - Stars Hingham
Burger Survey - Customer Review
Server: Wes
Ate on:       07/01/2010
Time:       7pm
Which Burger:       Cannonball
Burger Rating:       10
Burger Comments:       Yes I like the burger and I would try it again. Don't change a thing.

Commented:
It's possible that you have malformed headers...you may want to try removing the spaces before and after your \r and \n.

Alternatively, the recipient "gmail" may not see that you are sending the message from a valid server.  What is the hostname of your server and do you operate any other e-mail from this server.  Also, do you get similar messages when sending to other recipients?

 - flub
I did that and no go.

Would it help if I created the email: burgersurvey@starshingham.com - on the server?

I use this same script all the time and never get this.

Ryan

Commented:
Do you get the same problem when not sent to gmail?

 - flub
Weird...seems to be GMAIL only.. sent it to my other email address which is hosted at GoDaddy and it worked fine.

Ryan
Commented:
At this point, the code then is probably working.  My guess is that it is more of a configuration issue with your server (name resolution or that sort of thing) that is making it appear as spam on the g-mail servers.  

 - flub
I wonder if I create that email address if that will do it? Weird how it worked on another server but not GoDaddy, can you see anything off in my PHP?

Ryan
greetings catonthecouchproductions,, , I had sort of that problem, but I did Not get the kind of error message that you have shown. . . But I found out that the outgoing mail for the PHP mail( ), can be configured in different ways, SO, on one server that I was sending email, I could have anything in the "FROM" header, but on another server, it would only send mail if you had a working local email addy in the "FROM" header. . .
so you should try and create that email address,
also you should drop the @ in the "Burger Survey @ Stars Hingham" it may not cause problems, but you don't need it and it is a "Special" character in the email address syntax

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial