How To Send Mail Using PHP

Written by admin
if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subjectName = $_POST['Subject'];
    $message = $_POST['message'];

    $to = '';
    $subject = $subjectName;
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= ' demo from Website<>'."\r\n";
    $message = '<html>

			<span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">'.$message.'</span>
				<div class="container">
				 <table class="table table-bordered">
              mail($to, $subject, $message, $headers);

    echo '<script>alert("Email sent successfully !")</script>';
    echo '<script>window.location.href="mail.php";</script>';

<link href="" rel="stylesheet" id="bootstrap-css">
<div class="container">
        <div class="row centered-form">
        <div class="col-sm-4 ">
           <div class="panel panel-default">
              <div class="panel-heading">
                   <h3 class="panel-title">How to send Mail Using PHP</h3>
                   <div class="panel-body">
                   <form method="POST">
                            <div class="form-group">
                         <label for="name">Name</label>
                         <input type="text" name="name" id="name" class="form-control input-sm" placeholder="Name">
                      <div class="form-group">
                         <label for="email">Email</label>
                         <input type="email" name="email" id="email" class="form-control input-sm" placeholder="Email Address">
                      <div class="form-group">
                         <label for="Subject">Subject</label>
                         <input type="text" name="Subject" id="Subject" class="form-control input-sm" placeholder="Subject">
                      <div class="form-group">
                         <label for="message">Message</label>
                         <textarea id="message" name="message" rows="4" cols="50" class="form-control input-sm"></textarea>  
                        <div class="col-sm-6 ">
                               <input type="submit" name="submit" value="Submit" class="btn btn-info btn-block">
    <style type="text/css">
    background-color: #fff;
   margin-top: 60px;

.centered-form .panel{
   background: rgba(255, 255, 255, 0.8);
   box-shadow: rgba(0, 0, 0, 0.3) 20px 20px 20px;
How To Send Mail Using PHP With Source Code
Size: 1kb
Version: 5.1

About the author


Hi there! I'm Shiv Gupta. I specialized in building Websites. I write blogs in my free time. I really like to find out and share my knowledge with others.I founded ThePhpConcept in March 2020. I started this blog in order that I can interact with some like-minded people and also help people learning PHP, Mysql, jQuery, Html, and PHP Projects and related technologies.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.