Results 1 to 8 of 8

Thread: PHP form - is completely off its head

  1. #1
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile PHP form - is completely off its head

    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!

    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.";
    }


    ?>

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by suction cup
    PHP Code:
    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:
    PHP Code:
    // 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');


  4. #4
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by bluewalrus View Post
    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

  5. #5
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by traq View Post
    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


  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    "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.

  7. The Following User Says Thank You to traq For This Useful Post:

    suction cup (11-25-2010)

  8. #7
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    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.

  9. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by suction cup View Post
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •