Preface:
If you are a beginner in php and if you ever wanted to make a contact page that sends email to admin on submission then this post is for you.
This is a very simple Email Form in php that will help you to understand the process and would help you to make more complex forms.
Introduction:
There are two pages, Contact.html and SendMail.php,
Contact.html is a HTML form where the visitor will submit his name, email and message. and
SendMail.php will get the variables and would displatch email to admin containing all the information.
We will use PHP MAIL function for sending out email.
Following are the code for HTML Form called Contact.html
Contact.html
————
Quick Code
<html>
<title>Sample Contact Page</title>
<body>
<form action=SendMail.php method=post>
Name :: <input type=text name=uname>
Email :: <input type=text name=uemail>
Message ::
<textarea name=message rows=10 cols=20>Write your message here </textarea>
<input type=submit value="Send Email to Admin"> <input type=reset value="Clear">
</form>
</body>
</html></div>
Following is the code for SendMail.php that will accept form variables and will send Email.
SendMail.php
————
// define the email that you want to send the form
$to = “admin@yoursite.com”;
// Get form variables
$name = $_POST[uname];
$email = $_POST[uemail];
$msg = $_POST[message];
// make the body of email
$mailbody = “Name: $name
Email: $email
Message: $msg”;
// use mail function of php to send email
if (mail($to,“Contact Form Submitted from your site”,$mailbody,“\r\n From: $email”) ) {
echo “Email Sent successfully”;
}
else
echo “There was some problem in sending email please refer to manual”;
?>
Important Note: This is a very basic Tutorial to make an Email Based Contact Form in PHP and it is no alternative to a professionally writtern and secure contact form. The sole purpose of this tutorial is to give PHP newbies a quick start so that they can improvise to make complex php email based contact forms. I have already been running a very famous Email Based Contact Form project that is very secure and professionally written with standard code, email validation, user-friendly dynamic messages, form validation, CAPTCHA, Remote Spam Attacks Proof and it is recommended to download that code and study it and also you can use it right a way in your website as it is very elegant too.
Download Email Based Contact Form For FREE
Haroon (www.fastcreators.com)