How to send Mail Using PHP

  • Home
  •  / 
  • PHP
  •  / 
  • How to send Mail Using PHP

How to send Mail Using PHP

Step 1: You need to create a form

<!– start .contact-form –>
<div class=”contact-form”>
<form method=”post” >
<div class=”input-field”>
Name: <br><input type=”text” class=”form-control” name=”name” required=”” title=”Please Enter Your Name Here”>
<div class=”input-field”>
Email id: <br><input type=”email” class=”form-control” name=”email” required=”” title=”Please Enter Your Email Here”>
<div class=”input-field”>
Mobile: <br><input type=”text” class=”form-control” name=”mobile” required=”” maxlength=”10″ title=”Please Enter Your Mobile Number Here”>
<div class=”input-field”>
Subject: <br><input type=”text” class=”form-control” name=”subject” required=”” title=”Please Enter Your Subject Here”>
<div class=”input-field message”>
<textarea name=”message” class=”form-control” required=”” title=”Please Enter Your Message Here”></textarea>
<input type=”submit” name=”submit” class=”btn btn-success pull-right” value=”SEND” id=”msg-submit”>
<!– end .contact-form –>
Above I have mentioned a sample of the form through which you can send the mail.
Step 2: Create the code for sending email
<!–Email send start–>
$to = ““; // Email address
$cc = ““; // CC
$from = $_POST[’email’]; // Sender’s Email address
$name = $_POST[‘name’]; // Name
$mobile = $_POST[‘mobile’]; //Mobile Number
$subject = “Contact Us Form | Subject : ” . $_POST[‘subject’]; //Subject for Reciever
$subject2 = “Copy of your Contact Us form submission to¬†“; //Subject for Sender
$message = ” Name: ” . $name . “\n\n Email: ” . $from . “\n\n Mobile: ” . $mobile . “\n\n Subject: ” . $_POST[‘subject’] . “\n\n Message: ” . $_POST[‘message’]; //Message for Reciever
$message2 = “Hey: ” . $name . “\n\nHere is a copy of your message: ” . $_POST[‘message’]; //Message for Sender
$headers = “From:” . $from . “\r\n” . $cc;
//$headers = “From:” . $from; // This Header may use when you don’t want to insert CC
$headers2 = “From:” . $to;
mail($from,$subject2,$message2,$headers2); // Sends a copy of the message to the sender
echo “<script>alert(‘Mail Sent. Thank you ” . $name . “, we will contact you shortly.’)</script>”; // Submission popup
<!–Email send end–>

PHP Developer

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *