Log in

View Full Version : PHP form - is completely off its head



suction cup
11-24-2010, 12:34 AM
Please help! :)

I've been making a PHP form for an online booking system.

It used to work just fine, although it would take about 2 hours to send the messages.

Now; it seems to have given up! With no notice! :eek:

Honestly, any help with this would be so appreciated; I'm fairly new to programming. I've been through it checking for mistakes and changing things, trying things out; but no joy so far. There's probably something well obvious, like a colon in the wrong place...

Here's the site link: www.kabeoke.com

And here's the PHP; as emailme6.php:

<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}



$select=$_POST['select'];
checkOK($select);

$name=$_POST['name'];
checkOK($name);

$email=$_POST['email'];
checkOK($email);

$confirmail=$_POST['confirmail'];
checkOK($confirmail);

$month=$_POST['month'];
checkOK($month);

$day=$_POST['day'];
checkOK($day);

$year=$_POST['year'];
checkOK($year);

$leaving=$_POST['leaving'];
checkOK($leaving);

$hour=$_POST['hour'];
checkOK($hour);

$minutes=$_POST['minutes'];
checkOK($minutes);

$ampm=$_POST['ampm'];
checkOK($ampm);

$going=$_POST['going'];
checkOK($going);

$flightnumber=$_POST['flightnumber'];
checkOK($flightnumber);

$pay=$_POST['pay'];
checkOK($pay);

$song=$_POST['song'];
checkOK($song);

$comments=$_POST['comments'];
checkOK($comments);

$message="Message Type: $select\n\nName: $name\n\nEmail: $email\n\n$confirmail\n\nDate of Journey: $month, $day, $year\n\nLeaving From: $leaving\n\nDeparture Time: $hour:$minutes $ampm\n\nGoing to: $going\n\nFlight Number: $flightnumber\n\nPayment Method: $pay\n\nSong Requests: $song\n\nComments: $comments";

header('Location:http://www.kabeoke.com');

if(mail("beepbeepyeah@kabeoke.com","Slap it - booking/enquiry from Kabeoke.com!",$message,"From: $email\n")) {
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}


?>

bluewalrus
11-24-2010, 12:40 AM
Does it display the php code when you load it or is the page completely blank (verify from source view)? Is it just this page or all php pages?

traq
11-24-2010, 02:01 AM
header('Location:http://www.kabeoke.com');

if(mail("beepbeepyeah@kabeoke.com","Slap it - booking/enquiry from Kabeoke.com!",$message,"From: $email\n"))you are sending the user to another page before the script gets to the mail() function.

Strictly speaking, the mail will never be sent. In practice, the script might occasionally send it, but it will never be reliable. Simple change the order:


// remove the header() call

if(mail("beepbeepyeah@kabeoke.com","Slap it - booking/enquiry from Kabeoke.com!",$message,"From: $email\n")){
// and put it inside the if() statement,
// so it only redirects when the mail was sent successfully
header('Location:http://www.kabeoke.com');
}

suction cup
11-24-2010, 04:51 PM
Does it display the php code when you load it or is the page completely blank (verify from source view)? Is it just this page or all php pages?

I'm sorry; I don't understand the question.

Do you mean does it display any of the emailme6.php on Submit? When submitted, it returns to the homepage www.kabeoke.com; only, nothing comes through from the form by email.

Cheers

suction cup
11-24-2010, 04:58 PM
you are sending the user to another page before the script gets to the mail() function.

Strictly speaking, the mail will never be sent. In practice, the script might occasionally send it, but it will never be reliable. Simple change the order...



Hey Adrian; Thanks.

It was set up like that as I'd read somewhere that -header- had to come before any 'output' from the php script; I don't know if that includes -mail- commands. Apparently, stuff after -header- is processed. Anyway, I changed the order over as you suggested, though it hasn't solved it - still only about 1/10 of the forms 'sent' actually end up in the email inbox. Grrr; anyways, thanks for the assistance.

Cheers

:)

traq
11-24-2010, 09:20 PM
"output" means anything that is actually sent to the browser - anything echoed, printed, or a header() function, mostly.

The important thing in this case is that when you use header() to redirect the user to another page, they leave the current page. The script on the current page should just die, and usually does, but once in a while it finishes executing anyway.

If you emails are taking that long to send and aren't sending reliably, you should contact your host and see if there's any problems with the server.

suction cup
11-25-2010, 12:26 PM
Cheers Adrian; by the way I checked your link - do you do freelance projects? The booking form is getting updated to something javascripty (akin to the one here: http://www.cromwellcars.com/). Please let us know if you're interested.

traq
11-25-2010, 05:59 PM
Cheers Adrian; by the way I checked your link - do you do freelance projects? The booking form is getting updated to something javascripty (akin to the one here: http://www.cromwellcars.com/). Please let us know if you're interested.
you're welcome. and sure - PM'd