<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
if($_SERVER['REQUEST_METHOD'] == "POST"){
	foreach ( $_POST as $key => $value) {
		if($value=='') {
			header('location: ../index.html');
		}
	};


require 'PHPMailer/PHPMailerAutoload.php';

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

	$message = '
	<html lang="en">
	  <head>
	    <meta charset="UTF-8">
	    <title></title>
	  </head>
	  <body style="margin:0;" bgcolor="#f2f7ff">
	    <table style="WIDTH: 100%; BACKGROUND-color: #72B44A;" cellSpacing="0" cellPadding="0" width="100%" align="center" bgcolor="#f2f7ff" border="0">
	      <tr>
	        <td style="height: 15px" height="15">&nbsp;</td>
	      </tr>
	      <tr>
	        <td width="100%" valign="top">
	          <table style="border-top: #eaeff7 1px solid; border-right: #eaeff7 1px solid; border-bottom: #eaeff7 1px solid; border-left: #eaeff7 1px solid" cellSpacing="0" cellPadding="0" width="645" align="center" bgcolor="#ffffff">
	            <tr>
	              <td width="100%" valign="top">
	                <table style="border-top: #eaeff7 1px solid; border-right: #eaeff7 1px solid; border-bottom: #eaeff7 1px solid; border-left: #eaeff7 1px solid" cellSpacing="0" cellPadding="0" width="100%" align="center" bgcolor="#ffffff">
	                  <tr>
	                    <td style="border-top: #d9dee5 1px; border-right: #d9dee5 1px solid; border-bottom: #dadde2 1px solid; border-left: #d9dee5 1px solid" vAlign="top" width="100%" align="center">
	                      <table style="FONT-FAMILY: arial, verdana, sans-serif; color: #555;padding-bottom: 30px;" cellSpacing="0" cellPadding="0" width="600" bgcolor="#ffffff">
	                        <tr>
	                          <td width="100%" valign="top" style="padding-top:10px;">
	                            <p  style="FONT-SIZE: 16px; FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-WEIGHT: bold;MARGIN: 10px 0;LINE-HEIGHT: 20px; color: #555">
	                              Contact Form Email:
	                            </p>
	                            <p  style="FONT-SIZE: 16px; FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-WEIGHT: normal;MARGIN: 0px;LINE-HEIGHT: 20px; color: #555">
	                              Name: '.$name.'
	                              <br>Email: '.$email.'
	                              <br>Number: '.$phone.'
	                              <br>Subject: '.$subject.'
	                            </p>
	                            <p  style="FONT-SIZE: 16px; FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-WEIGHT: normal;MARGIN: 0px;LINE-HEIGHT: 20px; color: #555">
	                              <br>Comment: '.$message.'
	                            </p> 
	                          </td>
	                        </tr>
	                      </table>
	                    </td>
	                  </tr>
	                </table>
	              </td>
	            </tr>
	          </table>
	        </td>
	      </tr>
	    </table>
	  </body>
	</html>
	';

//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.speednetkhulna.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
//Username to use for SMTP authentication
$mail->Username = "email@speednetkhulna.com";
//Password to use for SMTP authentication
$mail->Password = "oA7ud8LMo6OS";
//Set who the message is to be sent from
$mail->setFrom($email , $name);
//Set an alternative reply-to address
$mail->addReplyTo($email ,$name);
//Set who the message is to be sent to
$mail->addAddress('info@speednetkhulna.com', 'SpeedNetKhulna');
$mail->AddCC('speednetkhulna@gmail.com', 'SpeedNetKhulna');
//Set the subject line
$mail->Subject = "Contact us";
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($message);

	//send the message, check for errors
	if (!$mail->send()) {
	    echo "NOK";
	} else {
	    echo "OK";
	}
      
}

?>