<?php

if (!$_POST) exit;

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

require_once '../vendor/phpmailer/src/Exception.php';
require_once '../vendor/phpmailer/src/PHPMailer.php';
require_once '../vendor/phpmailer/src/SMTP.php';

// passing true in constructor enables exceptions in PHPMailer
$mail = new PHPMailer(true);

$name     = $_POST['name'];
$email    = $_POST['email'];
$subject  = $_POST['subject'];
$phone    = $_POST['phone'];
$comments = $_POST['message'];

$mail = new PHPMailer();
$mail->IsSMTP();
// $mail->SMTPDebug = 1;
$mail->Mailer = 'smtp';
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
// $mail->Username = '';
// $mail->Password = '';
$mail->SMTPSecure = 'tls';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// $mail->From = '';
// $mail->FromName = '';
// $mail->AddAddress('');
$mail->WordWrap = 100;
$mail->IsHTML(true);
$mail->Subject = 'You\'ve been contacted by ' . $email . ' Name : ' . $name . '.';
$message_body = '
	<p>Dear Team,</p>
	<br>
	<p style="color:green";><b>Greetings...!</b></p>
	<br>
	<p>You have been contacted by <b>' . $email . '</b> Subject :' . $subject . ' their additional message is as follows. for this mail.</p>
	<p>' . $comments . '</p>
	<p> You can contact via email, ' . $email . ' or Name : ' . $name . ' or via phone : ' . $phone . '</p> 
	<br><p><b>NOTE: This is system generated mail. Please, do not reply. For any clarification please contact, </b>
	admin@saurashtracorp.com </p>
	<p> <b>Thanks.</b> </p>
	';

$mail->Body = $message_body;

if ($mail->Send()) {
	echo "<fieldset>";
	echo "<div id='success_page'>";
	echo "<h4>Email Sent Successfully.</h4>";
	echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us. As early as possible  we will contact you</p>";
	echo "</div>";
	echo "</fieldset>";
} else {
	echo 'ERROR!';
}
