Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with php email forms. Check me for errors?

Status
Not open for further replies.

tjtindal

Programmer
Mar 22, 2004
66
US
Okay, I'm using a feedback.php file on my website index directory, and I'm fairly sure it's working properly since it sends me to the 'thankyou.html' page afterwards. However, no mail sent from the page will end up at email@yahoo.com for some reason! (I have alternatively changed the email target to a different one, 'email@gmail.com,' but it's not going through either.) Would someone check the code for errors?

(And before you ask, I'm using Ripway.com and they do support php)

This is feedback.php
Code:
$mailto = 'email@yahoo.com' ;

// $subject - set to the Subject line of the email, eg
//$subject	= "Feedback Form" ;

$subject = "Realm of Gravity - Comment" ;

// the pages to be displayed, eg
//$formurl		= "[URL unfurl="true"]http://www.example.com/feedback.html"[/URL] ;
//$errorurl		= "[URL unfurl="true"]http://www.example.com/error.html"[/URL] ;
//$thankyouurl	= "[URL unfurl="true"]http://www.example.com/thankyou.html"[/URL] ;

$formurl = "[URL unfurl="true"]http://h1.ripway.com/GravityX/index.html"[/URL] ;
$errorurl = "[URL unfurl="true"]http://h1.ripway.com/GravityX/woops.html"[/URL] ;
$thankyouurl = "[URL unfurl="true"]http://h1.ripway.com/GravityX/thanks.html"[/URL] ;

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
	header( "Location: $formurl" );
	exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
	header( "Location: $errorurl" );
	exit ;
}

if (get_magic_quotes_gpc()) {
	$comments = stripslashes( $comments );
}

$messageproper =

	"This message was sent from:\n" .
	"$http_referrer\n" .
	"------------------------------------------------------------\n" .
	"Name of sender: $name\n" .
	"Email of sender: $email\n" .
	"------------------------- COMMENTS -------------------------\n\n" .
	$comments .
	"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
	"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>
 
nothing looks wrong other than the $mailto variable is not explicitly set. i'm assuming you took this out for the purposes of this post.

some suggestions though:

abandon the name <email> notation for testing purposes. Just include the email address in the From and Reply-To heading.

i am not clear whether you are using \r\n as the line terminators. if not, you should be.

and get rid of the X-Mailer for testing.

Code:
$header = "From: $email \r\nReply-To: $email \r\n";
mail($mailto, $subject, $messageproper, $header);

outside of the above, the next step is to debug the connection to the smtp server itself. have you successfully sent mail through the connection previously?
 
It may be that Yahoo! mail does not like the way the headers are formed. This can happen if you are using shared hosting as the return address set automatically by the web server is not the same as the from address.

Try setting a return-path by adding
Code:
-f myname@mydomain.com
to the headers.

However, I see that you are using Gmail as a test too. I've not had any issues with Gmail when not setting the return path so this might all be moot!






<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top