<?php
include '../testmail/class.smtp.php';
require_once('../testmail/class.phpmailer.php');

if($_POST) {

   $name = trim(stripslashes($_POST['contactName']));
   $email = trim(stripslashes($_POST['contactEmail']));
   $subject = trim(stripslashes($_POST['contactSubject']));
   $contact_message = trim(stripslashes($_POST['contactMessage']));

   // Check Name
	if (strlen($name) < 2) {
		$error['name'] = "Please enter your name.";
	}
	// Check Email
	if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
		$error['email'] = "Please enter a valid email address.";
	}
	// Check Message
	if (strlen($contact_message) < 15) {
		$error['message'] = "Please enter your message. It should have at least 15 characters.";
	}
   // Subject
	if ($subject == '') { $subject = "Contact Form Submission"; }


    // Set Message
   $message .= "Email from: " . $name . "<br/>";
   $message .= "Email address: " . $email . "<br/>";
   $message .= "Subject : " . $subject . "<br/>";
   $message .= "Message: <br />";
   $message .= $contact_message;
   $message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";

   if (!$error) {

        $mail = new PHPMailer();
        $config = array();
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'fourpillarsmfg.com';
        $config['smtp_user'] = 'info@fourpillarsmfg.com';
        $config['smtp_pass'] = 'EUIqLm]Kwp9~';
        $config['smtp_port'] = '25';
        //$mail->SetFrom($email,$name);
        $mail->SetFrom('info@fourpillarsmfg.com', $name);
        $mail->Subject = $subject;

        $mail->MsgHTML($message);
        //$siteOwnersEmail = "fourpillarsmfg18@gmail.com";
        $siteOwnersEmail = "rahul.hexasquad@gmail.com";

        $mail->AddAddress($siteOwnersEmail);
        if ($mail->Send()) {
            echo "OK";
        } else {
            //echo "Mailer Error: " . $mail->ErrorInfo;
            echo "Something went wrong. Please try again.";
        }

	} else {

		//$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
		$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
		//$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
		echo $response;

	} # end if - there was a validation error

}

?>