Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php/mysql help with form

Options
  • 22-08-2008 3:24pm
    #1
    Registered Users Posts: 788 ✭✭✭


    Hi,

    I have profiles set up dynamically on a website. Users can make a booking with each client that owns the profile. Their details are stored in the database, including their email address. The form works through a php file called booking. It was originally working and sending emails correctly but now it's not sending anything.

    this is my database code on the form page
    <?php $result=mysql("$DBName","SELECT * FROM profile WHERE id = '$id'");
    while($row=mysql_fetch_row($result)) {
    $id = $row[0];
    $tname = $row[1];
    $tdetails = $row[4];
    $pemail= $row[5];
    $tphone= $row[6];
    $taddress = $row[7];
    }
    
    ?>
    

    the form post was like this
    <form method="post" action="booking.php">
    

    All form names and id's look fine.


    the booking.php code is
    <?php
    
    $to = "$pemail";
    $name= $_REQUEST['name'];
    $email = $_REQUEST['email'] ;
    $phone = $_REQUEST['phone'];
    $subject = "Booking from $name <$email>";
    $address = $_REQUEST['address'];
    $date = $_REQUEST['date'];
    $time = $_REQUEST['time'];
    $comments = $_REQUEST['comments'] ;
    $headers = "From: $name <$email>";
    $message = "blah blah";
    $sent = mail($to, $subject, $message, $headers) ;
    if($sent)
    { header('Location: thankyou.html');
    }
    

    Anyone know how I can get it working again :confused:


Comments

  • Registered Users Posts: 2,534 ✭✭✭FruitLover


    Check your MTA logs.


  • Closed Accounts Posts: 382 ✭✭misterq


    It might be that php is no longer sending out mails for some reason.
    Try a test php script to send a mail to yourself and see if you can get that.

    You can also have it output more details errors so you can see what is going on.

    It is more than likely something that has changed on your hosting setup if the scripts have not been modified.


  • Registered Users Posts: 788 ✭✭✭sleepyescapade


    misterq wrote: »
    It might be that php is no longer sending out mails for some reason.
    Try a test php script to send a mail to yourself and see if you can get that.

    You can also have it output more details errors so you can see what is going on.

    It is more than likely something that has changed on your hosting setup if the scripts have not been modified.


    Works if I put my own email address in the $to section, but doesnt grab an email address or any other record from the database output on the previous form page


  • Registered Users Posts: 788 ✭✭✭sleepyescapade


    Nevermind got it working :)


  • Registered Users Posts: 788 ✭✭✭sleepyescapade


    Argghh, it now works but doesn't redirect to my thankyou page :(:(

    My new code;
    <form method="post" action="<?php echo "$pagename"; ?>">
    <input type="hidden" name="step" value="1">
    

    I have the pagename echoing as each page reloaded is dynamically renamed.
    if ($step == "1"){
    $to = "$temail";
    $name= $_REQUEST['name'];
    $email = $_REQUEST['email'] ;
    $phone = $_REQUEST['phone'];
    $subject = "Booking from $name <$email>";
    $address = $_REQUEST['address'];
    $date = $_REQUEST['date'];
    $time = $_REQUEST['time'];
    $comments = $_REQUEST['comments'] ;
    $message = "Hi,
    
    You have received a booking from $name.";
    
    $headers = "From: $name <$email>";
    $sent = mail($to, $subject, $message, $headers) ;
    Header("Location: ./thankyou.html");
    }
    ?>
    

    If I put thankyou.html as the action,it then shows up but the email does not send. Any help would be hugely appreciated, thanks!


  • Advertisement
  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Putting thankyou.html won't work simply because the PHP isn't being interpreted. (Not .php - I doubt you have your server set up for php to interpret .html but it is a possibility) - I bet if you went view source in your browser once you submit your form you'll see the php in plain text (ie just dumped out to browser).

    Rename thankyou.html to thankyou.php and it will then work.

    As for the redirection, I don't think you should have it as ./thankyou.html - try simply

    [php]Header("Location: thankyou.html");
    [/php]
    This is assuming thankyou.html is in the same directory as the file that contains that Header call. Still though you better off going the way you were originally submitting to thankyou.php

    Hope this helps :)


  • Registered Users Posts: 788 ✭✭✭sleepyescapade


    Thanks but no joy :( Server is set up to enable php in .html extensions also.


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    megcork wrote: »
    Thanks but no joy :( Server is set up to enable php in .html extensions also.
    Are you getting the value of step as:

    [php]
    $step = $_POST; //or using $_REQUEST
    [/php]

    ..before checking its value.

    Can you print out exactly all the code as it will be clear then.


  • Registered Users Posts: 788 ✭✭✭sleepyescapade


    Got this sorted, put ob_start(); at the top of my script :)


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Just noticed that now that you are outputting content (even a blank line) before the Header() function. This isn't allowed. You should always print headers out first before any content gets out.

    The reason it works with ob_start() is you are placing all output content into a buffer. This doesn't go to the web browser hense why it works.

    Ideally you should place the following block of code at the top of the page but after the block that gets the details from mysql as these are used there.

    [php]
    if ($step == "1"){
    $to = "$temail";
    $name= $_REQUEST;
    $email = $_REQUEST ;
    $phone = $_REQUEST;
    $subject = "Booking from $name <$email>";
    $address = $_REQUEST;
    $date = $_REQUEST;
    $time = $_REQUEST;
    $comments = $_REQUEST ;
    $message = "Hi,

    You have received a booking from $name.";

    $headers = "From: $name <$email>";
    $sent = mail($to, $subject, $message, $headers) ;
    Header("Location: ./thankyou.html");
    }
    ?>
    [/php]

    So by placing the following block of code before you output any HTML (before it) you can remove the ob_start().
    [php]
    <?php //make sure no lines before this. This is line 1 of the file.

    include('inc/header.php');
    require("admin/conf.php");
    mysql_connect("$DBHost","$DBUser","$DBPass");
    $request = explode("/",$_SERVER["REQUEST_URI"]);
    $pagename = $request[1];
    $tid=$_GET;
    $catname=$_GET;

    $step = $_POST;

    if ($step == "1"){
    $to = "$temail";
    $name= $_REQUEST;
    $email = $_REQUEST ;
    $phone = $_REQUEST;
    $subject = "Booking from $name <$email>";
    $address = $_REQUEST;
    $date = $_REQUEST;
    $time = $_REQUEST;
    $comments = $_REQUEST ;
    $message = "Hi,

    You have received a booking from $name.";

    $headers = "From: $name <$email>";
    $sent = mail($to, $subject, $message, $headers) ;
    Header("Location: ./thankyou.html");
    }
    ?>
    [/php]

    By the way you should have seen warnings that content was outputted before headers - I'm guessing you have warnings turned off in the php.ini file - I would advise to have these enabled when starting just so you can get hints to where the problems are.


  • Advertisement
Advertisement