Page 1 of 1

PHP Post Mail Form Problem

Posted: Mon Jun 05, 2006 5:07 pm
by jabucket
twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a customer of mine who has their own web/mail server. Recently, all PHP Post based mail forms have stopped functioning. No error is reported outside of the page that the user is directed to in the event of a failure in script processing (see code below):

Code: Select all

<?php
	$to = "aaron@domain.com";
	$subject = "Request - $name";
	$headers .= "MIME-Version: 1.0\r\n"; 
	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
	$headers .= "From: domain.com <admin@domain.com>\r\n"; 
	$headers .= "Reply-To: ".$name." <".$email.">\r\n"; 
	$headers .= "X-Priority: 1\r\n"; 
	$headers .= "X-MSMail-Priority: High\r\n";
	$headers .= "X-Mailer: iCEx Networks HTML-Mailer v1.0";
	$subject = stripslashes($subject);
	$message = stripslashes($message);
	$body = "<font face=Arial size=-1><b>$name</b> has submited a Franchise Information Request. <br><br>
	Name: <b>$name</b> <br>
	Address: <b>$address</b> <br>
	Comments: <br>$comments";
	$success = @mail($to,$subject,$body,$headers);
?>

<P>

<?php
if($success){
	include("sub_thanks.html");
}else{
	include("sub_error.html");
}
?>
All submissions redirect to the sub_error.html page. This is happening on 3 different scripts on this server, so I am assuming that it is not a code issue. Any ideas?

Jeff


twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jun 05, 2006 5:13 pm
by Chris Corbyn
I hope $email, $body, $to etc etc are not comming from POST?

Use $_POST. Register Globals needs to be on for that to work and it's bad bad bad bad bad!! :twisted: (especially here -- I see no sanity checking at all).

Posted: Mon Jun 05, 2006 5:49 pm
by jabucket
Was able to get an error message out of it:

Notice: Undefined variable: headers in E:\domains\cp\sendmail.php on line 4

Notice: Undefined variable: message in E:\domains\cp\sendmail.php on line 12

I have similar scripts to this running on other servers which are working fine. Not sure why it isn't here. I checked and register_globals is turned on.

Jeff

Posted: Mon Jun 05, 2006 5:58 pm
by Chris Corbyn
Where does $message appear from? Can we see the form. Even with regsiter_globals on you want to start using $_POST... I'm not kidding, relying upon register globals is a huge security risk.

Posted: Mon Jun 05, 2006 6:23 pm
by jabucket
Moving to windows server group. Thanks for the tip on the $_POST. I will make that change ASAP. I uploaded the script to another server and it works great, so there must be a problem with this particular server. Sorry to have posted in the wrong group, though the tip I came away with may have made it worth the mistake. :D

Thanks

Posted: Tue Jun 06, 2006 2:51 am
by twigletmac
The @ in front of the mail() function is suppressing any errors that function might be generating so it would be useful to change:

Code: Select all

$success = @mail($to,$subject,$body,$headers);
to

Code: Select all

$success = mail($to,$subject,$body,$headers);
Mac

Posted: Tue Jun 06, 2006 3:14 am
by twigletmac