Add to Google

A Full Error Protected Php Contact Form

free web hosting
Open Discussion > CONTRIBUTE > Tutorials

A Full Error Protected Php Contact Form

skter4938
Well hello there yound lads. This is my first tutorial ever. If you would like to see the finished product for yourself please go to http://www.webtodesign.net/contact/


Anyways here we go!

Step 1. Make a file called index.php. This is where the form is going to be. Copy and paste this code in:
CODE

<?php session_start(); ?>
<!--Start error code-->
<?php
if ($_SESSION['error_msg']) {
foreach ($_SESSION['error_msg'] as $val) {
echo "$val<br />";
}
unset($_SESSION['error_msg']);
}
?>
<!--End Error Code-->

<!--Start Form Code-->
                
<form method="POST" action="contact.php">
                                
<p><label for="Name">Name</label><br />
<input id="Name" name="Name" type="text" tabindex="1" size="30" /></p>
                
<p><label for="EmailFrom">Email</label><br />
<input id="EmailFrom" name="EmailFrom" type="text" tabindex="2" size="30" /></p>
                
<p><label for="Subject">Subject</label><br />
<input id="Subject" name="Subject" type="text" tabindex="3" size="30" /></p>
                            
<p><label for="words">Message</label><br />
<textarea name="Message" tabindex="5" rows="10" cols="24" style="width:300px;"></textarea></p>
                
<input type="submit" name="post" id="post" value=" Send " />  <input type="reset" value=" Reset " />
</form>
<!--End Form Code-->


The first part tells the document to start the session. MAKE SURE YOU PUT THIS IN THE VERY BEGGINING BEFORE ANYTHING ELSE!!!

Now let me try and explain. Then the second part of the code, the error checking part, checks if there is an error, such as someone not entering their name or an email which is not valid. For example. If someone decided to be a stupid and enter this for an email "alkjdldaslkjas", it will display "Please enter in a valid email". Anyways, if you try it out you will see what I am talking about.

Now the second part of the code is just the form, which is self explanitory.




Step 2. Ok now make a file called contact.php. This is the part of the script that will process the form. Here is the code:
CODE

<?php

session_start();
//Email Validation
function checkEmail($email)
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
   {
      return FALSE;
   }

   list($Username, $Domain) = split("@",$email);

   if(@getmxrr($Domain, $MXHost))
   {
      return TRUE;
   }
   else
   {
      if(@fsockopen($Domain, 25, $errno, $errstr, 30))
      {
         return TRUE;
      }
      else
      {
         return FALSE;
      }
   }
}


// get posted data into local variables
$EmailTo = "youremail@domain.com";
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$Name = Trim(stripslashes($_POST['Name']));
$Subject = Trim(stripslashes($_POST['Subject']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if(checkEmail($EmailFrom) == FALSE){
$error_msg[] = "Please enter in a valid email address.";
}
if (Trim($Name)==""){
$error_msg[] = "Please enter in a name.";
}
if (Trim($Subject)=="") {
$error_msg[] = "Please enter in a subject.";
}
if (Trim($Message)==""){
$error_msg[] = "Please enter in a message.";
}
//triggers error message
if ($error_msg) {
$_SESSION['error_msg'] = $error_msg;
header ('Location: index.php');
exit();
}
//sends email
else {
$Body = "You have a new email from $Name.\n\n Reply to $EmailFrom.\n\n $Name says,\n $Message";
$success = mail($EmailTo, $Subject, $Body);
}
//redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_done.php\">";
}
else{
  print "Email could not be sent due to errors. Please email the <a href='mailto:youremail@domain.com>webmaster</a>.";
}
?>


MAKE SURE YOU REPLACE YOUREMAIL@DOMAIN.COM WITH YOUR EMAIL ADDRESS

Ok so this is the part where the script check to see if the form is filled out nice and neatly, with a proper email and all that good stuff. It then emails you what the person wrote and voila! It works!!! It also relocates to a page called contact_done.php.

You can make the contact_done.php file if you want to. That file just tells the viewer that their submission has been sent correctly and that all is dandy. If you do not want to make it, just remove this part of the code:
CODE
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_done.php\">";




PLEASE TELL ME IF YOU FIND AN ERROR


Thank you very much for checking out my tutorial and good luck with future coding laugh.gif

Download the script - Click to view attachment

Notice from Johnny:
Approved.

 

 

 


Reply

Hadi
Wow!! Nice tutorial, thank you very much. As I see you are very good at this (coding, scripting, php etc...) on the contrary I barely now how to code. How di you showed the number of download on your post? It's really cool. Keep up the good work!

Reply

Plenoptic
Very nice tutorial. Usually when I get a php contact form I mess it up some how but this is the full and real thing. Thanks for posting it. Good job.

Reply

SolarX
I often thought about implementing something like this, but I always put it on the bottom of my list wink.gif

But thanks to your tutorial, I will implement it right now.
thanks in advance smile.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. open succes page contact form php - 473.04 hr back. (1)
  2. php contact form with error checking - 804.16 hr back. (1)
  3. error - 1034.22 hr back. (1)
  4. wp-contact form protected - 1074.47 hr back. (1)
  5. php contact form success page - 1314.57 hr back. (1)
  6. php contact form bold - 1670.89 hr back. (1)
Similar Topics

Keywords : full, error, protected, php, contact, form

  1. How To Design A Contact Form In Flex Part Duex Part 2
    (0)
  2. How To Design A Contact Form In Flex Part Duex Part 1
    (1)
    How to Design a Contact Form in Flex Part Duex Part 1 Well if you had read my first three
    tutorials on how to design a contact form, you learn some basics on MXML and of course design a
    contact form. Yeah I promise a part 4 to that series, that is why I renamed this one to Part Duex,
    since the form is completely different, and using a different way to populate my combo boxes with
    data. Although, I might have found something to get the php going for this, but I save that for
    another time. Now because I am using the flex editor to design my contact form, I will be re....
  3. Design A Contact Form In Flex Part 3
    (2)
    Design A Contact Form In Flex Part 3 Hopefully you have able to get a grasp on my first tutorials
    on how to design a flex form and then be able to stylize it with CSS. So now on to set up your form
    to validate and of course being able to reset your form as well., and before we get to the actual
    coding I break down the tags that will be used in this tutorial and what their roles are. Of course,
    since my newbieness really starts here I try my best to explain these tags. The first tag I will
    cover for setting up the validation is the tag, and since I don't underst....
  4. Design A Contact Form In Flex Part 2
    (0)
    Design A Contact Form In Flex Part 2 I hope that you learn a little bit of the Flex format with my
    first tutorial because that was the easy stuff until you get to the actual programming such as
    ActionScript and any other languages. Of course, I think this is by far the easiest part of
    designing forms or applications and that is using CSS. I will like to point out that CSS in Flex is
    a enigma and I will tell you why, because CSS in flex acts like regular CSS in html however it is
    very limited in what you can use and yet CSS in Flex is very complex because of how you ca....
  5. Design A Contact Form In Flex Part 1
    (0)
    Design a Flex Form Part 1 Well this is my first tutorial on Adobe Flex 3 which is a great program
    if you’re interested in designing applications for the web 2.0 era. Adobe flex is the way to
    go as it combines several different programming languages in order to make the most out of this
    program. This includes HTML, CSS, XML, PHP/MySQL, XML, ActionScript, Ruby on Rails and ASP and this
    is all possible by the use of MXML or Magic eXtensible Markup Language because it is a user
    interface markup language. My three part tutorials for this form include designing the f....
  6. Wordpress Contact Form That Work With Free Web Hosts
    (1)
    Hi there, I had a bit of trouble setting up the wp-contact-form plugin for my wordpress blog that
    was hosted by freehostia. At first I was using the free package, so I couldn't send out any
    mail. I solved that by saving all messages to a directory, and password protecting it. When I
    updated to a payed package, I still couldn't send out any mail. It turned out that the From
    header had to be an existing email that I had registered with my freehostia account, and
    wp-contact-form used "From: " I solved that by modifying the plugin, changing From to the
    administrat....
  7. Psp Error- Tut On How To Fix
    When you try to use the internet does your psp get an internal error? (32)
    First of all, psp can browse the internet with its simple browser. BUT! What you may not know is
    that there is a bug where when you try to search or use a wireless lan connection (WLAN) the psp may
    say something like: Internal Error (80410A0B) To fix this without any memory loss, take out the
    UMD which is in the psp, and also take out the memory card. Next, go to settings, then system
    settings and click restore settings, the psp may freeze up, but it is not broken, take out the
    batter pack and put it back in, the settings should be restored and all should work. So....
  8. 404 Error Page
    Learn to make a really cool one (4)
    First, you should know a little bit of basic PHP. It is relatively simple. CODE echo $_SERVER
    ; echo $_SERVER ; ?> echo $_SERVER ; - Displays users browser. echo $_SERVER ; - Displays
    users IP Address. If you have a PHP host, put in CODE phpinfo(); ?> and in one of the
    sections, there are a whole bunch like these. Like display where user came from etc.
    Experiment...and you can create something like Hey! What are you trying to do, buddy?! I know you
    are using Microsoft Internet Explorer! Your IP is 192.168.0.0! So don't keep trying or we will h....
  9. Custom 404 Error Pages
    A Tutorial On How To Make Custom 404 Error Pages (17)
    I've seen a tutorial on here and no offense but it was horrific, this is the real way you do a
    404 Error Page. Make a file called: htaccess.txt Open it up and put this: CODE ErrorDocument
    404 /myerrorpage.html You will need to change myerrorpage.html to whatever your page is called.
    Also when you upload this file to your server you need to rename it to: .htaccess Yes, the dot is
    before the words. You need to do this on the server because on Windows you cannot do that!....
  10. ---> Ftp Error Codes What They Mean <---
    (5)
    CODE FTP Error Messages some nice info about ftp error codes so you know what they mean. i am
    sure you see them all the time and sometimes you dont know what they mean, so take a look here. The
    most common codes: 421 - often means: too many users logged to the same account. 530 - wrong
    login:pass, some servers auto-switch to 530 from 421 when they reach the max # of users. so notice
    the error message attached to the code. 550 - common in Ratio site, If the file exsist it means you
    have no access to the file or dir. if you try changing dirs in an FTP and you`re g....
  11. Php Emailer/contact System
    An email or contact system for your site (20)
    Hello all, Here is an easy Emailer or Contact system that allows visitors or members of your site
    to email you just by filling out a form. So here is what you need to do to set it up. First open up
    a new page in your text editor and paste in the following code. CODE $Name = $_POST ; $Subject
    = $_POST ; $Email = $_POST ; $Site = $_POST ; $Message=$_POST ; $align = $_POST ; $to = "$EmailTo";
    $subject = "$Subject"; $body = "$Message\n\n\n$Site\nBy: $Name"; $headers = "From: $Email\n";
    mail($to,$subject,$body,$headers); // After they've clicked "Send", this is whe....

    1. Looking for full, error, protected, php, contact, form






*SIMILAR VIDEOS*
Searching Video's for full, error, protected, php, contact, form

*MORE FROM TRAP17.COM*
advertisement



A Full Error Protected Php Contact Form



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE