fixed whitespace
fixed whitespace

--- a/class.mailer.php
+++ b/class.mailer.php
@@ -1,14 +1,17 @@
 <?php
 
-/*
-*   Author 		: Razvan Stanga
-*   Date    	: 03/08/2009
-*   Description	: Sends MIME emails, TXT/HTML/Attachments
-*
-*/
+/**
+ * Mailer
+ *
+ * Sends MIME emails, TXT/HTML/Attachments
+ *
+ * @category    Mail
+ * @package     Mailer
+ * @author      Razvan Stanga <git@razvi.ro>
+ */
 
 class Mailer {
-	
+
 	private $cc;
 	private $bcc;
 	private $html;
@@ -16,50 +19,49 @@
 	private $attachments;
 	private $params;
 	private $charset;
-	
+
 	private $smtp_helo;
 	private $smtp_host;
 	private $smtp_port;
 	private $smtp_msg;
 	private $smtp_log;
 	private $smtp_conn;
-    private $smtp_user;
-    private $smtp_pass;
-	
+	private $smtp_user;
+	private $smtp_pass;
+
 	private $sender;
 	private $from;
 	private $to;
 	private $replyto;
 	private $returnpath;
-	
+
 	private static $instance = array ();
 	public $IB		= false;
- 	public $ORDER   = 1000;
-	
+	public $ORDER   = 1000;
+
 	public function __construct () {
 		$this->cc = array ();
 		$this->bcc = array ();
 		$this->attachments = array ();
 		$this->params = "";
 	}
-	
+
 	public static function getInstance ($id="default") {
 		if( self::$instance[$id] == null) {
-        	self::$instance[$id] = new self;
-      	}
-      	return self::$instance[$id];
-    }
-
-	function init () {
-
-	}
-	
+			self::$instance[$id] = new self;
+		}
+		return self::$instance[$id];
+	}
+
+	public function init () {
+	}
+
 	public function setSMTP ($host, $port, $log=0) {
-		$this->smtp_host = $host;
-		$this->smtp_port = $port;
-		$this->smtp_log = $log;
-	}
-	
+		$this->smtp_host	= $host;
+		$this->smtp_port	= $port;
+		$this->smtp_log	 = $log;
+	}
+
 	public function setHELO ($helo) {
 		if ( $helo ) {
 			$this->smtp_helo = $helo;
@@ -67,12 +69,12 @@
 			$this->smtp_helo = $this->smtp_host;
 		}
 	}
-    
-    public function setSASL ($smtp_user, $smtp_pass) {
-        $this->smtp_user = $smtp_user;
-        $this->smtp_pass = $smtp_pass;
-    }
-	
+
+	public function setSASL ($smtp_user, $smtp_pass) {
+		$this->smtp_user = $smtp_user;
+		$this->smtp_pass = $smtp_pass;
+	}
+
 	public function setTo ($email, $name="") {
 		if ( $name ) {
 			$this->to = "\"".$name."\" <".$email.">";
@@ -80,7 +82,7 @@
 			$this->to = $email;
 		}
 	}
-	
+
 	public function setFrom ($email, $name="") {
 		if ( $name ) {
 			$this->from = "\"".$name."\" <".$email.">";
@@ -88,7 +90,7 @@
 			$this->from = $email;
 		}
 	}
-	
+
 	public function setSender ($email, $name="") {
 		if ( $name ) {
 			$this->sender = "\"".$name."\" <".$email.">";
@@ -96,7 +98,7 @@
 			$this->sender = $email;
 		}
 	}
-	
+
 	public function setReplyTo ($email, $name="") {
 		if ( $name ) {
 			$this->replyto = "\"".$name."\" <".$email.">";
@@ -104,15 +106,15 @@
 			$this->replyto = $email;
 		}
 	}
-	
+
 	public function setReturnPath ($email) {
 		$this->returnpath = $email;
 	}
-	
+
 	public function setCharset ($charset) {
 		$this->charset = $charset;
 	}
-	
+
 	public function setCC ($email, $name="") {
 		if ( $name ) {
 			$this->cc[] = "\"".$name."\" <".$email.">";
@@ -120,7 +122,7 @@
 			$this->cc[] = $email;
 		}
 	}
-	
+
 	public function setBCC ($email, $name="") {
 		if ( $name ) {
 			$this->bcc[] = "\"".$name."\" <".$email.">";
@@ -128,11 +130,11 @@
 			$this->bcc[] = $email;
 		}
 	}
-	
+
 	public function setAttachment ($name, $path) {
 		$this->attachments[$name] = $path;
 	}
-	
+
 	public function setSubject ($subject) {
 		if ( function_exists ('mb_internal_encoding') ) {
 			mb_internal_encoding ($this->charset);
@@ -141,11 +143,11 @@
 		}
 		$this->subject = $subject;
 	}
-	
+
 	public function setHTML ($html) {
 		$this->html = $html;
 	}
-	
+
 	public function setTXT ($txt) {
 		$this->txt = $txt;
 	}
@@ -153,46 +155,44 @@
 	public function setParams ($params) {
 		$this->params = $params;
 	}
-    
+
 	public function clearLog ($clear=1) {
-        if ( $clear == 1 ) {	   
-            $this->smtp_msg = "";
-        }
-	}
-	
-	private function _open_smtp_conn() {
-		if ($this->smtp_conn = @fsockopen ($this->smtp_host, $this->smtp_port)){
-			if (in_array($this->_get_smtp_response(), array(220, 250, 354))){
+		if ( $clear == 1 ) {
+			$this->smtp_msg = "";
+		}
+	}
+
+	private function _open_smtp_conn () {
+		if ( $this->smtp_conn = @fsockopen ($this->smtp_host, $this->smtp_port) ){
+			if ( in_array ($this->_get_smtp_response(), array(220, 250, 354)) ){
 				return true;
 			}
 		}
 		return false;
 	}
 
-	private function _extract_email($parse) {
-		preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $parse, $matches);
-		if (count($matches[0]) == 1){
+	private function _extract_email ($parse) {
+		preg_match_all ("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $parse, $matches);
+		if ( count ($matches[0]) == 1 ){
 			return $matches[0][0];
-		}
-		elseif (!count($matches[0])){
+		} elseif ( !count ($matches[0]) ){
 			return false;
-		}
-		else {
+		} else {
 			return $matches[0];
 		}
 	}
 
-	private function _close_smtp_conn() {
-		$this->_send_smtp_command("QUIT");
-		@fclose($this->smtp_conn);
-	}
-
-	private function _send_smtp_command($command, $number="") {
-		if (@fwrite($this->smtp_conn, $command . "\r\n")){
-			$this->smtp_msg .= $this->smtp_log == true ? $command . "\n" : "";
-			if (!empty($number)){
-				if (!in_array($this->_get_smtp_response(), (array)$number)){
-					$this->_close_smtp_conn();
+	private function _close_smtp_conn () {
+		$this->_send_smtp_command ("QUIT");
+		@fclose ($this->smtp_conn);
+	}
+
+	private function _send_smtp_command ($command, $number="") {
+		if ( @fwrite ($this->smtp_conn, $command . "\r\n") ){
+			$this->smtp_msg .= $this->smtp_log == true ? $command . "\r\n" : "";
+			if ( !empty ($number) ) {
+				if ( !in_array ($this->_get_smtp_response(), (array)$number) ) {
+					$this->_close_smtp_conn ();
 					return false;
 				}
 			}
@@ -201,40 +201,40 @@
 		return false;
 	}
 
-	private function _get_smtp_response() {
+	private function _get_smtp_response () {
 		do {
-			$response = chop(@fgets($this->smtp_conn, 1024));
-			$this->smtp_msg .= $this->smtp_log == true ? $response . "\n" : "";
-		} while($response{3} == "-");
-		return intval(substr($response,0,3));
-	}
-
-	private function _smtp_send($headers, $body) {
-		if ($this->_open_smtp_conn()){
-			if (!$this->_send_smtp_command("helo {$this->smtp_helo}", array(220, 250, 354))){return false;}
-			if(!empty($this->smtp_user) && !empty($this->smtp_pass)){
-				if (!$this->_send_smtp_command("EHLO {$this->smtp_host}", array(220, 250, 354))){return false;}
-				if (!$this->_send_smtp_command("AUTH LOGIN", array(334))){return false;}
-				if (!$this->_send_smtp_command(base64_encode($this->smtp_user), array(334))){return false;}
-				if (!$this->_send_smtp_command(base64_encode($this->smtp_pass), array(235))){return false;}
-			}
-			if (!$this->_send_smtp_command("MAIL FROM:" . $this->returnpath, array(220, 250, 354))){return false;}	// FixBug: http://www.developarts.com/version_14_de_nomad_mime_mail#comment-19
-			$all_email = $this->_extract_email(implode(", ", array($this->to, implode (", ", $this->cc), implode (", ", $this->bcc))));
-			foreach ((array)$all_email as $email){
-				if (!$this->_send_smtp_command("RCPT TO:{$email}", array(220, 250, 354))){return false;}
-			}
-			if (!$this->_send_smtp_command("DATA", array(220, 250, 354))){return false;}
+			$response = chop (@fgets($this->smtp_conn, 1024));
+			$this->smtp_msg .= $this->smtp_log == true ? $response . "\r\n" : "";
+		} while ($response{3} == "-");
+		return intval (substr ($response,0,3));
+	}
+
+	private function _smtp_send ($headers, $body) {
+		if ( $this->_open_smtp_conn () ){
+			if ( !$this->_send_smtp_command ("helo {$this->smtp_helo}", array(220, 250, 354)) ) {return false;}
+			if ( !empty ($this->smtp_user) && !empty ($this->smtp_pass) ) {
+				if ( !$this->_send_smtp_command ("EHLO {$this->smtp_host}", array(220, 250, 354)) ) {return false;}
+				if ( !$this->_send_smtp_command ("AUTH LOGIN", array(334)) ) {return false;}
+				if ( !$this->_send_smtp_command (base64_encode ($this->smtp_user), array(334)) ) {return false;}
+				if ( !$this->_send_smtp_command (base64_encode ($this->smtp_pass), array(235)) ) {return false;}
+			}
+			if ( !$this->_send_smtp_command ("MAIL FROM:" . $this->returnpath, array(220, 250, 354)) ) {return false;}
+			$all_email = $this->_extract_email (implode(", ", array($this->to, implode (", ", $this->cc), implode (", ", $this->bcc))));
+			foreach ((array)$all_email as $email) {
+				if ( !$this->_send_smtp_command ("RCPT TO:{$email}", array(220, 250, 354)) ) {return false;}
+			}
+			if ( !$this->_send_smtp_command ("DATA", array(220, 250, 354)) ) {return false;}
 			$this->_send_smtp_command ($headers);
 			$this->_send_smtp_command ($body);
-			if (!$this->_send_smtp_command (".", array(220, 250, 354))){return false;}
-			$this->_close_smtp_conn();
+			if ( !$this->_send_smtp_command (".", array(220, 250, 354)) ) {return false;}
+			$this->_close_smtp_conn ();
 			return true;
 		}
 		return false;
 	}
 
 	public function send ($debug=false) {
-  		if ($this->replyto == '') {
+		if ( $this->replyto == '' ) {
 			$this->replyto = $this->from;
 		}
 
@@ -247,8 +247,8 @@
 		} else {
 			$headers .= "Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
 		}
-		
-  		$headers .= "From: ".$this->from."\r\n";
+
+		$headers .= "From: ".$this->from."\r\n";
 		$headers .= "Reply-To: ".$this->replyto."\r\n";
 		$headers .= "Sender: ".$this->sender."\r\n";
 		$headers .= "X-Mailer: razvi.ro/svn/mailer\r\n";
@@ -268,28 +268,28 @@
 
 		// message
 		$message = "This is a multi-part message in MIME format.\r\n\r\n";
-		
+
 		// if there are attachments, add custom boundary for message
 		if ( count ($this->attachments) && ($this->txt || $this->html) ) {
-            $message .= "--".$boundary."\r\n";
-            $pre = "msg-";
-            $message .= "Content-Type: multipart/alternative; boundary=\"".$pre.$boundary."\"\r\n\r\n";
+			$message .= "--".$boundary."\r\n";
+			$pre = "msg-";
+			$message .= "Content-Type: multipart/alternative; boundary=\"".$pre.$boundary."\"\r\n\r\n";
 		} else {
 			$pre = "";
 		}
-		
+
 		// txt message
 		if ( $this->txt ) {
-   			$message .= "--".$pre.$boundary."\r\n";
+			$message .= "--".$pre.$boundary."\r\n";
 			$message .= "Content-Type: text/plain; charset=\"".$this->charset."\"\r\n";
-			$message .= "Content-Transfer-Encoding: 8bit\n";
+			$message .= "Content-Transfer-Encoding: 8bit\r\n";
 			$message .= "\r\n";
 			$message .= $this->txt;
 			$message .= "\r\n\r\n";
 		}
 		// html message
 		if ( $this->html ) {
-    		$message .= "--".$pre.$boundary."\r\n";
+			$message .= "--".$pre.$boundary."\r\n";
 			$message .= "Content-Type: text/html; charset=\"".$this->charset."\"\r\n";
 			$message .= "Content-Transfer-Encoding: 8bit\r\n";
 			$message .= "\r\n";
@@ -320,17 +320,16 @@
 		if ( $this->smtp_host ) {
 			$this->_smtp_send ($headers, $message);
 		} else {
-	        @mail ($this->to, $this->subject, $message, $headers, $this->params);
-       	}
+			@mail ($this->to, $this->subject, $message, $headers, $this->params);
+		}
 		if ( $debug == true ) {
-            exit ();
-		}        
-	}
-    
-    public function _smtp_msg () {
-        return $this->smtp_msg;
-    }
+			exit ();
+		}
+	}
+
+	public function _smtp_msg () {
+		return $this->smtp_msg;
+	}
 }
 
-
 ?>

comments