<?php session_start();

if (isset($_POST["op"]) && ($_POST["op"]=="send")) {  

	//if(!empty($_SESSION['6_letters_code'] ) && strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) == 0 )

	//{	

		/******** START OF CONFIG SECTION *******/

		$subject1 = "Contact Form - 1 Direction Melbourne"; // need to change

		// Select if you want to check form for standard spam text

		$SpamCheck = "Y"; // Y or N

		$SpamReplaceText = "*content removed*";

		// Error message prited if spam form attack found

		$SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.

		</font><br><b>Your IP Number of <b>".getenv("REMOTE_ADDR")."</b> has been logged.</b></p>";

		/******** END OF CONFIG SECTION *******/

		// need to change

		$name		    = $_POST['name']; 

		$suburb			= $_POST['suburb'];

		$phone		    = $_POST['phone'];

		$email		    = $_POST['email'];

		$comments	    = $_POST['comments'];


		if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {

				

				} else { ?>

					<script type="application/javascript">

					window.location="thankyou.php?send=2#page";

					</script>

				<?php	exit();

		}

		if ($SpamCheck == "Y") 

			{		   

			// Check for Website URL's in the form input boxes as if we block website URLs from the form,

			// then this will stop the spammers wastignt ime sending emails

			if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}

			if (preg_match("/http/i", "$address")) {echo "$SpamErrorMessage"; exit();} 

			if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();} 

			if (preg_match("/http/i", "$phone")) {echo "$SpamErrorMessage"; exit();} 

			if (preg_match("/http/i", "$comments")) {echo "$SpamErrorMessage"; exit();} 

			

			// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer 

			$pattern = '/(;|\||`|>|<|&|^|"|'."\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string 

			

			$name = preg_replace($pattern, "", $name);

			$address = preg_replace($pattern, "", $address);

			$email = preg_replace($pattern, "", $email); 

			$phone = preg_replace($pattern, "", $phone); 

			$comments = preg_replace($pattern, " ", $comments); 

			

			// Check for the injected headers from the spammer attempt 

			// This will replace the injection attempt text with the string you have set in the above config section

			$find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i"); 

			$name = preg_replace($find, "$SpamReplaceText", $name);

			$address = preg_replace($find, "$SpamReplaceText", $address);

			$email = preg_replace($find, "$SpamReplaceText", $email); 

			$phone = preg_replace($find, "$SpamReplaceText", $phone); 

			$comments = preg_replace($find, "$SpamReplaceText", $comments); 

			

			// Check to see if the fields contain any content we want to ban

			if(stristr($name, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 

			if(stristr($comments, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 

			

			// Do a check on the send email and subject text

			//if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 

		}


			$email1	= "enquiry@1directionaustralia.com.au"; // need to change

			$mail_content = '

			<html xmlns="http://www.w3.org/1999/xhtml">

			<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

			

			<title>Notification Of Job Invitation</title>

				<style>

				body{

				font-family:Arial, Helvetica, sans-serif;

				font-size:14px;

				width:800px;

				height:auto;	

				color:#2F2F2F;

				line-height:20px;

				float:left;

				border:2px solid #CCC;

				padding:20px;

				border-radius:10px;

				-webkit-border-radius:10px;

				-moz-border-radius:10px;

				}

				figure{

				float:right;

				}

				.wrap_01{

				float:left;

				}

				.highlight{

				font-size:15px;

				color:#06C;

				}

				.highlight a {

				text-decoration:none;

				color:#06C;

				}

				.high_01{

				font-weight:bold; color:#06C;

				}

				.address{

				font-size:13px;

				float:left;

				}

				.address p{

				line-height:5px;

				}

				.title{

				font-size:30px;

				

				font-weight:bold;

				color:#00A1EB;

				}

				.footertxt{

				padding:0px;

				margin:0px;

				color:#333;

				font-size:12px;

				}

				</style>

			</head>

			<body>

				<div class="wrap_01">

				Enquiry from the website 1 Direction Melbourne.

				<p> <span class="high_01">Name</span> : '.$name.'.</p>

				<p> <span class="high_01">Email-Id</span> : '.$email.'.</p>

				<p> <span class="high_01">Phone</span> : '.$phone.'</p>

				<p> <span class="high_01">Suburb</span> : '.$suburb.'</p>

				<p> <span class="high_01">Message</span> : '.$comments.'</p>

				<div style="border-bottom:1px solid #00A1EB; padding-bottom:10px; margin-top:60px; width:800px; margin-bottom:20px;"> <span class="title" >Nextweb Technologies</span> </div>

				</div>

			</body>

			</html>';

			//error_reporting(E_ALL);

			error_reporting(E_STRICT);

			//date_default_timezone_set('America/Toronto');

			require_once('mailer/class.phpmailer.php');

			//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

			$mail             = new PHPMailer();

			//$body             = file_get_contents('contents.html');

			$body = $mail_content;

			//$body             = preg_replace('/[\]/','',$body);

			
            $mail->IsSMTP(); // telling the class to use SMTP
		$mail->Host       = "1directionaustralia.com.au"; // SMTP server
		$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
												   // 1 = errors and messages
												   // 2 = messages only
		$mail->SMTPAuth   = true; 
	//	$mail->SMTPSecure = "ssl";    // enable SMTP authentication
		$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
		$mail->Username   = "enquiry@1directionaustralia.com.au"; // SMTP account username
		$mail->Password   = "enquiry123!";  // SMTP account password
			$mail->SetFrom($email1, $name);
			$mail->AddReplyTo($email,$name);
			$mail->Subject    = $subject1;

			//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test


			$mail->MsgHTML($body);


			$address1 = "info@onedirectionaustralia.com.au"; 

			$mail->AddAddress($address1, "Info");

			$mail->AddCC("nawoda@onedirectionaustralia.com.au", "Nawoda");		

			$mail->AddBCC("reports@nextweb.com.au", "Reports");

			$mail->AddBCC("nextwebaustralia@gmail.com", "NextWeb");

		
			if(!$mail->Send()) {

			   //echo "Mailer Error: " . $mail->ErrorInfo; exit; 
			   ?>

				<script type="application/javascript">

				window.location="thankyou.php?send=0#page";

				</script>

			<?php } else { 

			$bname		= "1 Direction Melbourne"; // need to change

			$name 		= $name;

			$email		= $_REQUEST['email'];

			$suburb		= $suburb;

			$phone		= $phone;

			$message   	= $comments;

			$c_name		= "1 Direction Melbourne"; // need to change

			$c_phone	= "1300520417"; // need to change

			$website	= $_SERVER['HTTP_HOST'];

			$c_email	= "info@onedirectionaustralia.com.au"; // need to change


			session_destroy();

			include("autoreply.php");

			  //echo "Message sent!";

			?>

			<script type="application/javascript">

					window.location="thankyou.php?send=1#page";

				 </script>

		<?php }

}

?>
