Forum Moderators: coopster

Message Too Old, No Replies

Trouble migrating form from PHP 4 to 5

         

subgenius

3:36 pm on Jan 4, 2008 (gmt 0)

10+ Year Member



My company is changing hosts, and I'm having problems updating the code for our contact form from PHP 4 to 5. More specifically, the form was working on my old host, who ran PHP 4.4.7, but does not work on my new host, running 5.2.4.

One change I already made was shortening "$HTTP_POST_VARS" to "$_POST", but otherwise I'm stuck. If it helps, the front end for our form is a Flash (SWF) file. I've sent several tests, but have not received any of them.

Thanks in advance for any advice.

<?php
if(!empty($_POST['sender_message']))
{
$to = "info@companyname.com";
$subject = stripslashes($_POST['sender_subject']);

$body .= "\n\n--------------------------------------------------\n" .
"CONTACT FORM" .
"\n--------------------------------------------------\n" .
"Name: " . $_POST['sender_name'] . "\n" .
"Address: " . $_POST['sender_address'] . "\n\n" .
"Daytime Phone: " . $_POST['sender_phoneDay'] . "\n" .
"Email: " . $_POST['sender_email'] . "\n\n" .
"City: " . $_POST['sender_city'] . "\n" .
"State: " . $_POST['sender_state'] . "\n\n" .
"Zip: " . $_POST['sender_zip'] . "\n" .
"More Info: " . $_POST['info'] . "\n" .
"\n--------------------------------------------------\n" .
"Message: " . $_POST['sender_message'] .
"\n--------------------------------------------------\n";

$header .= "From: " . $_POST['sender_name'] . " <" . $_POST['sender_mail'] . ">\n";
$header .= "Reply-To: " . $_POST['sender_name'] . " <" . $_POST['sender_mail'] . ">\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";

if(@mail($to, $subject, $body, $header))
{
echo "output=sent";
} else {
echo "output=error";
}
} else {
echo "output=error";
}
?>

mikesmith76

4:52 pm on Jan 4, 2008 (gmt 0)

10+ Year Member



What errors do you get when you run the page? Do you have error reporting turned on?

subgenius

7:51 pm on Jan 4, 2008 (gmt 0)

10+ Year Member



I think error reporting is turned on, but I'm not seeing any errors. Part of the problem with seeing the errors is that the Flash file is where all the fields are, and as long as the Flash file gets the appropriate input from the user, and as long as there's a contactForm.php file on the web server, the Flash won't report any errors.

I've also changed the ".=" to just "=" for the variable $body and the first $header variable. It didn't fix the problem, but I think that's the correct way to format the code. I'm still searching online for other clues.

RonPK

8:27 pm on Jan 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try inserting

error_reporting(E_ALL);

at the top of your code, and build a HTML form to post whatever your Flash app would post.

Also, have you verified that

mail()
really works on the new server?

Also 2, your script is quite vulnerable to email header injection, as it doesn't sanitize user input. You might want to look into that...

whoisgregg

11:14 pm on Jan 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Even with error_reporting cranked up, you may not see any error until you remove the error control operator [php.net] "@" from your mail function.