How to make Fully functional Contact Form in php using mail() function ?

Description: In this example I’m gonna show you guys how to make fully functional contact form in php using mail() function. And in this example we also cover how to change the placeholder color, how to make captcha code and then will verify if the captcha code is same as you typed in.

I make this contact form for the holding page for my client  the kensington dentist, London.

And most important thing is this contact form is build in Zurb Foundation to make it fully responsive you guys can also use twitter bootstrap….

This example includes 4 different files:-
1. index.php   (In which we make our form)
2. send.php   (through which we’ll send the form it includes mail() function)
3. foundation.css  (its a zurb foundation css file to make the form responsive)
4. app.css  (this will be our custom stylesheet where we’ll give styling to input types and to the placeholders)

————————————————————————————————-
1. index.php

<?php
//  For captcha 
$aa = md5( time() * microtime() );
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Contact form</title>
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, user-scalable=0"/>
<link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,100italic,300italic,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="app.css"/>
<link rel="stylesheet" type="text/css" href="foundation.css"/>
</head>
<body>
   
       
                           
                   
                       
                                                   
                       
                                                    
                    </div>                                         
                       
                                                 
                       
                                                    
                    </div>                 </div>                                 
                   
                                           
                </div>                
                    
                        " readonly />                    
                </div>                
                    
                                                 
                </div>                
                   
                                           
                </div>                 
                   
                       

                       

                   
                </div>             </form>         </div>     </div> </div> </body> </html>

2. send.php

<?php
    if($_REQUEST['captcha'] != $_REQUEST['check'])
       {
            header("Location: index.php?error=The characters you entered didn't match the word verification. Please try again.");
       }
    else
       {
            $myemail = "mukul.soni0007@gmail.com";  /*ENTER THE EMAIL ADDRESS WHERE YOU WANT TO RECIEVE THE MAILS. In this case I set it to my personal gmail account. You can also make it dynamic by using $_REQUEST['the name of the field'] */
           
           $name = $_POST['fname'];
           $sname = $_POST['sname'];
           $subject = "Contact Form Submission";    /* Or you can make it dynamic by using $_POST['name of the field'] */
           $email = $_POST['mail'];
           $message = $_POST['message'];
           $tel = $_POST['tel'];
           
           $message="
           Name : $name $sname
           E-mail : $email
           Subject : $subject
           Telephone : $tel
           Message : 
           $message
           ";
           
           /* Send the message using mail() function */
           if(mail ($myemail, $subject, $message))
           {
           
           /* Redirect visitor to the page you guys want */
           header("Location: index.php?success=Thanks! We'll get back to you soon");
           exit(); 
           }
           else{
           /*If any error then throw an error.*/
               echo "Some error Occured !";
               exit();
           } 
       }
?>

3. foundation.css

You guys will find foundation.css here

4. app.css

.cb
{
    border:1px solid #000;
}
.posts-contact ::-webkit-input-placeholder {
   color: #24292d;
    opacity: 0.7;
}

.posts-contact :-moz-placeholder { 
   color:  #24292d;  
}

.posts-contact ::-moz-placeholder { 
   color:  #24292d;  
}

.posts-contact :-ms-input-placeholder {  
   color:  #24292d;  
}

.posts-contact
{
    
    max-width:504px;
    margin:34px auto;
    margin-bottom:0px;
    
}
#captcha
{
    background-color:#fff;
    font-size: 20px;
    font-weight:bold;
    text-shadow: 2px 0px 5px #5ca8fe;
    font-family:'Lato', sans-serif;
    color:rgba(0,0,0,0.5);
    letter-spacing: 10px;
}
.posts-contact input[type="text"],
.posts-contact input[type="tel"],
.posts-contact input[type="email"],
.posts-contact textarea
{
    background-color:#fff;
    box-shadow: 0px 0px 0px;
    text-shadow: none;
    color:rgba(0,0,0,0.75);
    font-family:'Lato', sans-serif;
    border:1px solid #c7c7c7;
    letter-spacing: 1px;
}
textarea
{
    font-family:'Lato', sans-serif;
}
input[type='submit']
{
    background-color:#75b4e2;
    width:171px;
    height:48px;
    border:1px solid #4484b4;
    color:#fff;
    font-family:'Lato', sans-serif;
    font-weight:bold;
    margin-top:28px;
}
input[type='submit']:hover
{
    cursor:pointer;
}
#error
{
    color:#f00;
    font-size:17px;
    padding: 5px;
    font-family: "Lato",sans-serif;
}
#success
{
    color:#2add37;
    font-size:17px;
    padding:5px;
    font-family: "Lato",sans-serif;
}

Note:-
1. Please whenever you use this contact form please change the email address inside send.php file which is wrapped in $myemail variable otherwise I’ll get all your mails.
2. It is possible that you can not find the mail in your inbox. So don’t forget to check spam folder
3. Keep all 4 files in the same folder.
4. You need a server to check this. Without server its just a static contact form. It will work only online.
If you want to see the live example of this form you can go to my testing server i.e jaiupur4ever .

To watch the video of php mail function

Advertisements

3 thoughts on “How to make Fully functional Contact Form in php using mail() function ?

    • Hi Syed !
      I updated code please re-copy and past it as it is and then check it’s working fine.
      In this updated version if it do not send email or if there is any error while sending mail then it will throw the pre-defined error which I hard coded in the else part of send.php so that you’ll find if there is any error or not.
      And if it shows success message then check your inbox or your spam folder after few seconds.
      I made it dynamically on the following link. so that you can enter your email address and able to receive mail from my server. And if the mail is not in your inbox then please check your spam folder.
      Here is the link:-
      http://jaipur4ever.in/contactform/

      -Thanks 🙂

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s