PHP Simple Contact Form Script

This is a sample script to insert a generic contact form into your website.
You can easily modify the script, in order to use different fields or to modify the style.
(nota: is uses just plain mail() PHP command, so deliverability of the sent message may be quite poor)

<?php 
$action=$_REQUEST['action']; 
if ($action=="")    
    ?> 
    <form  action="" method="POST" enctype="multipart/form-data"> 
       <input type="hidden" name="action" value="submit"> 
       Name:<br> 
       <input name="name" type="text" value="" size="35"/><br> 
       Email address:<br> 
       <input name="email" type="text" value="" size="35"/><br> 
       Your message:<br> 
       <textarea name="message" rows="8" cols="40"></textarea><br> 
       <input type="submit" value="Send email"/> 
    </form> 
    <?php 
    }  
else                /* send the data */ 
    { 
    $name=$_REQUEST['name']; 
    $email=$_REQUEST['email']; 
    $message=$_REQUEST['message']; 
    if (($name=="")||($email=="")||($message=="")) 
        { 
        echo "Error! All fields are required, please fill <a href=\"\">the form</a> again."; 
        } 
    else{         
        $from="From: $name<$email>\r\nReturn-path: $email"; 
        $subject="Message sent using your contact form"; 
        mail("[email protected]", $subject, $message, $from); 
        echo "Thank you for your message!"; 
        } 
    }   
?> 


  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

What do I need to do to put Flash on my website?

Flash is a client side feature - it runs on the user's computer, not on your web host. As long as...

What are private nameservers and how do I set them up?

Private nameservers are where your domain points to our nameservers so that your customers do not...

Static IP vs. Dynamic IP Address

A static IP address is one that remains fixed and never changes. The PC always sees the same...

Protecting Yourself Against Viruses & Data Loss

It is vital to ensure your computer is protected from viruses and trojans. As well as...

How to Upgrade perl?

Run the following command. cd /usr/local/src ; wget...