How To Send Mail Using PHP

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

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

			<body>
			<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">
				<tr><td>Name</td><td>'.$name.'</td></tr><tr><td>Email</td><td>'.$email.'</td></tr><tr><td>Subject</td><td>'.$subjectName.'</td></tr><tr><td>Message</td><td>'.$message.'</td></tr>
				</table>
                
                  
				</div>
			</body>
			</html>';
              mail($to, $subject, $message, $headers);

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


<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" 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>
                   <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>
                      <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>
                      <div class="form-group">
                         <label for="Subject">Subject</label>
                         <input type="text" name="Subject" id="Subject" class="form-control input-sm" placeholder="Subject">
                      </div>
                    
                      <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>
                     
                        <div class="col-sm-6 ">
                               <input type="submit" name="submit" value="Submit" class="btn btn-info btn-block">
                              
                         </div>
                          
                   </form>
                </div>
             </div>
          </div>
       </div>
    </div>
    <style type="text/css">
       body{
    background-color: #fff;
}
.centered-form{
   margin-top: 60px;
}

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

About the author

admin

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.
Support-thephpconcept@gmail.com

Leave a Comment

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