<?php
	require_once('source/session.php');
	require_once('source/error.php');
	require_once('source/dbconfig.php');
	require_once('source/function.php');
	
	if(isset($_POST['post_news']))
	{
		try {
			$news_title	= strip_tags($_POST['news_title']);
			$news	    = strip_tags($_POST['news']);
			$email	    = strip_tags($_POST['email']);


				sql($DBH, "INSERT INTO tbl_news (news_title, news, date, email, news_status) VALUES (?, ?, ?, ?, ?)", array($news_title, $news, $DATE_NOW,$email,"MESSAGE SENT"));
				
				
					// Subject
					$subject = 'AMERICAN JET CARGO';
					
					// Message
					$message = '<html>
									<head>
									  <title>$news_title</title>
									</head>
									<body>
									  <p>$email</p>
									</body>
								</html>';
					
					// To send HTML mail, the Content-type header must be set
					$headers[] = 'MIME-Version: 1.0';
					$headers[] = 'Content-type: text/html; charset=iso-8859-1';
					
					// Additional headers
					$headers[] = 'To: <'.$email.'>';
					$headers[] = 'From: AJC <noreply@americanjetcargo.com>';
					/*$headers[] = 'Cc: birthdayarchive@example.com';
					$headers[] = 'Bcc: birthdaycheck@example.com';*/
					
					// Mail it
					mail($email, $subject, $message, implode("\r\n", $headers));

				redirect('notice.php?msg=post');
		}
		catch(PDOException $e) { 
			file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); # Errors Log File
				redirect('notice.php?msg=failed');
		}
	}
	else
	{
				redirect('notice.php?msg=failed');
	}
?>