How to send email through php ?

Description:- In this example I’m gonna show you guys how to make your own fully functional custom contact us form for your own site. So this example is done in two different parts.
Step1:- The HTML part, which is the form and we named that form.php
Step2:- The php part and we named that email.php

*NOTE :-  To run this example you have to purchase your own hosting server. IT WON’T WORK OFFLINE…..

Step1:-   form.php

<!DOCTYPE html>
<title>Sending email</title>
<link rel="stylesheet" href="bootstrap.min.css" type="text/css"/>
<script src="bootstrap.min.js" type="text/javascript"></script>
<script src="jquery-1.11.1.min.js" type="text/javascript"></script>
<div class="container" style="margin:5% auto">
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4" style="box-shadow:1px 1px 1px 2px #CCCCCC; border-radius:1%; padding:3%;">
<form role="form" action="email.php" method="post">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control"/>
<div class="form-group">
<label for="email">Email</label>
<input type="text" name="email"  class="form-control"/>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="5"></textarea>
<input type="submit" name="sub" value="Send" class="btn btn-primary pull-right"/>
<div class="col-lg-4"></div>
<?php echo $_REQUEST['do']; ?>

 Step2:-  email.php

    $admin = "This msg came from Mr/Ms: ".$_REQUEST['name']. "<br/>"
            . "His/Her email address is: ".$_REQUEST['email']. "<br/>"
            . "His/Her message is: ".$_REQUEST['message'];
    mail('', 'Sample subject for this example', $admin); 
    //In this example I entered "" just for the example, you write your own valid mail address. 
    //In for the sample I entered "Sample subject for this example" for this example you write your own subject line.
    header("location:form.php?do=Thanks for your valuable message. We'll contact you as soon as possible");
    header("location:form.php?do=Please try again");

*NOTE :-  To run this example you have to purchase your own hosting server.


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s