Stop & Shout


MEMBER OF:



Get Paid Money to Blog


Feedback Form (PHP) Script
Thursday, 16 April 2009

Scenario #1:
Web Server's PHP version doesn't support $_REQUEST
Solution: Use $_GET (NOTE: careful in using this method on sensitive transaction)

Scenario #2: Web Server's execution time is set to 30sec (max), hence the error, Fatal error: Maximum execution time of 30 seconds on "http://....sendmail.php"
Solution: set_time_limit(60)

Saving and sharing my HTML/form code and sendmail.php here for my reference (took me a while to solve it, getting rusty na!).

****************************************** HTML ******************************************

<form method="get" action="sendmail.php">
<input type="text" name="name" value="Name:" />
<input type="text" name="mail" value="E-mail:" />
<textarea name="message" cols="30" rows="60">Message:</textarea>
<input type="submit" /> 
</form>


****************************************** sendmail.php ******************************************

<?php
 
  set_time_limit(60);
 
  $name = $_GET['name'];
  $email = $_GET['mail'];
  $message = $_GET['message'];
   
  if (empty($email) || empty($message))
      {
    ?>
        <html>
        <head><title>Error</title></head>
        <body>
        <h1>Error</h1>
        <p>
        Oops, it appears you forgot to enter either your
        email address or your message. Please press the BACK
        button in your browser and try again.
        </p>
        </body>
        </html>
    <?php
      }
  else
  {
    mail( " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ", "Feedback from your website", $message, "From: $name <$email>" );
    // redirect back to url visitor came from or
    // header( "Location: http://www.yoursite.com/thankyou.html" );
    header("Location: $HTTP_REFERER");
  }
   
?>

******************************************
No one has commented on this article.
Please keep your comments brief and on topic, and remember that this is not a discussion thread.
Name :
E-mail :
Website :
Comment(s) :
J! Reactions 1.09.00 • General Site License
Copyright © 2006 S. A. DeCaro
 
Next >