Liam Delahunty: Home Tips Web Contact
Recommended laptop
under £500

Think I deserve a present? See my Amazon Wish List

Click here for an alternative form with further anti-spam measures.

Click to see the contact form.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<style type="text/css">
.err {
   background-color: #cccccc;
   font-weight: bold;      

<h2>Contact Us</h2>

// put the emails of recipients here.
// seperate multiples by a comma,
// leave it alone for script to try and work it out.
$domain_name = eregi_replace("www.","",$SERVER_NAME);
$email_to = "contact@$domain_name";

// now this bit is a little bit clever it ASCII encodes
// the above email addresss for a link. (@ LINE 102)
// It's to help stop spambots from harvesting your email address.
function ascii_encode($str){
global $encoded;
for ($i=0; $i < strlen($str); $i++){
$encoded .= '&#'.ord(substr($str,$i)).';';

// this function just displays the errors, you need a
// class ".err" in the css for it to highlight properly.
// I've put a little something in above...

function err_display($err_array, $err){
   if ($err_array["$err"]){
      print ("<tr class=err>");
      print ("<tr>");

if (!isset($referer_url)){
   // let's try something!
   $referer_url = $HTTP_REFERER;

if ($submit){
   // do some testing?
      if ($first_name == ""){
         $err_array[first_name] = "<b>Error</b> please complete your first name.";
      if ($last_name == ""){
         $err_array[last_name] = "<b>Error</b> please enter your last name.";

      if ($email != "" ){
         $email = trim($email);
            $err_array[email] = "<b>Sorry</b> your email address ($email) doesn't appear to be valid";
         $err_array[email] = "<b>Error</b> please enter your email address.";

      $err_count = count($err_array);
      if ($err_count != 0){
         print ("<p class=err>Please correct the $err_count error(s):");
            while (list($index,$value) = each($err_array)){
               print ("$value<br>");
         print ("</p>");
         while (list($key,$val) = each($HTTP_POST_VARS)){
            $message .= "$key: $val\n";
            print ("$key: $val<br>");

         $email_headers = "From: $email\n";
         $email_subject = "Contact form";
         // this sends the email using the standard php mailer (sendmail?)
         @mail($email_to, $email_subject, $message, $email_headers);
         // Here's your thank you note...
         print ("<h2>Thank you $firstname!</h2>");

if (!$submit OR $err_count != "0"){
   print ("<p>Please use the form to send a message to <a href=\"mailto:$encoded\">$encoded</a></p>");
   print ("<form action=\"contact.php\" method=\"POST\">");
   print ("<table>\n<tr>");
   err_display($err_array, first_name);
   print ("<td>First name: (required)</td><td><input type=\"text\" size=14 size=14 name=\"first_name\" value=\"$first_name\"></td></tr>\n<tr>");
   err_display($err_array, last_name);
   print ("<td>Surname: (required)</td><td><input type=\"text\" size=14 name=\"last_name\" value=\"$last_name\"></td></tr>");
   print ("<tr>");
   err_display($err_array, email);
   print ("<td>Email: (required)</td><td><input type=\"Text\" name=\"email\" value=\"$email\"></td></tr>\n");
   print ("<tr><td>Subject: </td><td><input type=\"Text\" name=\"email_subject\" value=\"$email_subject\"></td></tr>\n");
   err_display($err_array, comments);
   print ("<td>Comments</td><td><textarea name=\"comments\" cols=\"25\" rows=\"6\">$comments</textarea></td></tr>\n");
   print ("<tr><td>How did hear about us?</td><td><input type=\"Text\" name=\"hear_about_us\" value=\"$hear_about_us\"></td></tr>\n");
   print ("<tr><td>Would you like to receive our occasional newsletter?</td><td><input type=\"Checkbox\" name=\"newsletter\"></td></tr>\n");
   print ("<tr><td>&nbsp;</td><td><input name=\"submit\" type=\"Submit\" value=\"Send\"></td></tr>\n");
   print ("</table>");
   print ("<input type=\"Hidden\" name=\"referer_url\" value=\"$referer_url\">");
   print ("</form>");


Share this!  

Php Checkdnsrr | Php Contact Form | Php Contact Form Anti Spam


  Tips | Home | Search | Contact

Link here: