ADVERTISEMENT


Breaking News

Recent Posts

Saturday, December 6, 2014

How to create contact us page in php

send email with phpIts very easy to send email from php  , it just taking your golden five minutes to send email from php, and  you can use it for multi purpose in your site.
e.g
- Contact Us page  or send any alerts to your customers or any activity emails etc.

creat html file  and chose it name as you wish like "index.html" and paste below html in it.

(this example relate to contact us page.)
<form method="post" action="contact.php">
 Email: <input name="email" type="text">
<br> Message:<br>  <textarea name="message" rows="15" cols="40"></textarea><br> 
 <input type="submit"> 
 </form>

In this form user have two fields Email, and message you cna add more as per requirments.
This form will send data in page "Contact.php" as mentioned in action.

so you have to create php file with same name mentioned in action of html form .
and paste below php code to send email.


<?php 
 $to = "you@yoursite.com";
 $subject = "Contact Us"; 
 $email = $_REQUEST['email'] ;  
 $message = $_REQUEST['message'] ;  
 $headers = "From: $email"; 
 $sent = mail($to, $subject, $message, $headers) ;  
if($sent)  {print "Your mail was sent successfully"; } 
else 
 {print "We encountered an error sending your mail"; } 
?>

we have ignored from email from html form because its sometime irritating and can be used for spam

No comments:

Post a Comment

Designed By Published.. Blogger Templates