I send PHP mail via SMTP

I send PHP mail via SMTP

Step – 1: First you add PHPMailer Class From GITHUB https://github.com/PHPMailer/PHPMailer/releases/tag/v6.1.2

Step – 2: add Form

<form class="form-area contact-form text-right" action="mail.php" method="post">
	<div class="row">	
	  <div class="col-lg-6 form-group">
           <input name="name" id="name"  placeholder="Enter your name" class="common-input mb-20 form-control"  type="text">
	   <input name="email" id="email" placeholder="Enter email address"   class="common-input mb-20 form-control"  type="email">
           <input name="sub" id="sub" placeholder="Enter subject"  class="common-input mb-20 form-control"  type="text">
       <div class="col-lg-6 form-group">
	   <textarea class="common-textarea form-control" name="desc" id="desc" placeholder="Enter Messege" ></textarea>				
       <div class="col-lg-12">
	   <button class="genric-btn primary" value="submit" id="submit" name="submit" style="float: right;">Send Message</button>											

Step – 3: Mail Configuration

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'mailerClass/Exception.php';
require 'mailerClass/PHPMailer.php';
require 'mailerClass/SMTP.php';
require 'mailerClass/PHPMailerAutoload.php';

try {

    $mailBody="Contact Us,<br/><br/><br/>Name:".$name."<br/>Email: ".$email."<br/>Message:".$sub."<br/>Message:".$desc."<br/><br/>Thank You.";

  $mail = new PHPMailer;   
  $mail->SMTPDebug = 0;     // Enable verbose debug output
  $mail->Host = 'relay-hosting.secureserver.net';  // Set mailer to use SMTP  if use localhot  ssl://smtp.gmail.com
  $mail->SMTPAuth = false;  // Enable SMTP authentication
  $mail->Username = 'GMAIL USERNAME';   // SMTP username
  $mail->Password = 'PASSWORD';     // SMTP password
  $mail->SMTPSecure = false; // Enable TLS encryption, `ssl` also accepted
  $mail->Port = 25; // TCP port to connect to use in localhost port use 587 or 465
    $mail->setFrom('Gmail Address', 'Demo');
    $mail->addAddress('Gmail Address');     // Add a recipient
    $mail->isHTML(true);      // Set email format to HTML
    $mail->Subject = 'Contact Us';
    $mail->Body    = $mailBody;

	if ($mail->send()) 
		 echo "<script type='text/javascript'>alert('Mail Send successfully..');</script>";
		 header("Location: index.php");
            echo "<script>setTimeout(\"location.href = 'index.php';\",10);</script>";
            echo "<script type='text/javascript'>alert('Message could not be sent. Mailer Error!..');</script>";
    catch (Exception $e)