<?php 
error_reporting(0);
/*------------------- mailer.php -------------------,
| * spam filter										|
| * Version		: 1.1.6							|
| * Developer	: Rejeesh							|
| * Email		: rejeeshonline@gmail.com			|
| * Updated		: 20-may-2014						|
'--------------------------------------------------*/
require_once(dirname(__file__)."/PHPMailer/class.phpmailer.php");
require_once(dirname(__file__)."/PHPMailer/extras/htmlfilter.php");
require_once(dirname(__file__)."/PHPMailer/extras/class.html2text.php");

class mailer{

public $mail;
public $SMTPDebug;
public $to;
public $to_name;
public $from;
public $from_name;
public $Subject;
public $data;
public $body;
public $template;



var $SMTPAuth = true;
/* var $Host = "mail.couturecommunity.com";
 var $Port = 25; //Set the SMTP port number - likely to be 25, 2626 or 587
 var $Username = "admin@couturecommunity.com";
 var $Password = "9RcmMGWaT[Zi";*/
 //var $SMTPDebug = 1;
var $Host = "prosentry.co.uk";
 var $Port = 587; //Set the SMTP port number - likely to be 25, 2626 or 587
 var $Username = "authenticate@prosentry.co.uk";
 var $Password = "uZXKaWpnoG)d";
 var $SMTPSecure = "SSL"; // SSL or TLS
	
	
	var $SpamReplaceText = "*content removed*";
	var $SpamErrorMessage;
	
	function __construct(){
		$this->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>";
		
		$this->mail = new PHPMailer(); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
	}

	function attachment($tpath, $path )
	{
	//	$this->mail->AddAttachment($path  );
		$this->mail->AddAttachment( $tpath, $path );
	}


	function Send(){
		$Subject 	= $this->escape($this->Subject);
		
		$this->body = file_get_contents($this->template);
		
	
		
		foreach($this->data as $key => $val) $this->body = str_replace("|@|".$key."|@|",$val,$this->body);
		//die($this->body);
		
		$this->body = HTMLFilter($this->body,"images/");
		//$html2text = new html2text($this->body);
		//$altbody = $html2text->get_text();

		//$this->body		= eregi_replace("[\]",'',$this->body);

		// smtp authentication
		if($this->SMTPAuth){
			$this->mail->IsSMTP();
			$this->mail->SMTPAuth = $this->SMTPAuth;
			$this->mail->SMTPSecure = $SMTPSecure;
			$this->mail->Host = ($SMTPSecure=="SSL"?"ssl://":"").$this->Host;
			$this->mail->Port = $this->Port;
			$this->mail->Username = $this->Username;
			$this->mail->Password = $this->Password;
		}else{
			$this->mail->IsSendmail();
		}
		
		$this->mail->SMTPDebug  = $this->SMTPDebug;
		$this->mail->Debugoutput = 'html';

		$this->mail->Subject = $Subject;
		//$this->mail->AltBody = $altbody; // optional - MsgHTML will create an alternate automatically
		$this->mail->MsgHTML($this->body);
		//$this->mail->AddAttachment('images/phpmailer.gif');      // attachment
		//$this->mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
		return $this->mail->Send();
		
		
		/*$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers .= "From: $this->from" . "\r\n" .
		"Reply-To: $from" . "\r\n" .
		'X-Mailer: PHP/' . phpversion();
		return mail($this->to,$Subject,$this->body,$headers);*/
		
		
	}
	
	function setTo($to, $to_name){
		$this->to = $to;
		$this->to_name = $to_name;
		$this->mail->AddAddress($this->escape($to), $this->escape($to_name));
	}

	function setFrom($from, $from_name){
		$this->from = $from;
		$this->from_name = $from_name;
		$this->mail->AddReplyTo($this->escape($from), $this->escape($from_name));
		$this->mail->SetFrom($this->escape($from), $this->escape($from_name));
		$this->mail->AddReplyTo($this->escape($from), $this->escape($from_name));
	}
	
	function setCC($from, $from_name){
		$this->mail->AddCC($this->escape($from), $this->escape($from_name));
	}
	
	function setBCC($from, $from_name){
		$this->mail->AddBCC($this->escape($from), $this->escape($from_name));
	}

	function clear(){
		$this->mail->ClearAllRecipients(); 
		$this->mail->ClearReplyTos();
		$this->mail->ClearCustomHeaders();
	}
	
	function escape($str){
		// 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", "$str")) {echo "$this->SpamErrorMessage"; exit();}
		
		// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer 
		$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string 
		
		$str = preg_replace($pattern, "", $str); 
		
		// 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"); 
		$str = preg_replace($find, "$this->SpamReplaceText", $str);
		
		return $str;
	}
	
}

$mailer = new mailer();

?>