Location: PHPKode > projects > Epiware Document Management > Epiware_4.8.6/epi/epi_mail.inc.php
<?
/******************************************************************************
Epiware: Project and Document Management
http://www.epiware.com
Copyright (C) 2006 James Kern

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. 

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. 

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Epiware, Inc. and Praxis Inc, hereby disclaims all copyright
interest in the program 'Epiware' written
by James Kern, Edward Kline, Ryan Gilfether, Ray Gorospe, Patrick Waddingham

06 September 2006
James Kern, President of Epiware 
Jack Chapman, President of Praxis
*****************************************************************************/ 
require_once("phpmailer/class.phpmailer.php");
//require_once("./phpmailerclass.smtp.php");

class MAILER extends phpmailer
{

	function MAILER()
	{	
		//$this->Mail = new phpmailer();
		$this->PluginDir = "./phpmailer/";
		$this->setLanguage("en",$this->PluginDir."language/");
		if(defined("SMTP_HOST"))
		{
			$this->Host = SMTP_HOST;
			$this->Port = SMTP_PORT;
			$this->Mailer = "smtp";
			$this->Helo = defined("WEB_SERVER")?WEB_SERVER:"localhost.localdomain";

			if(defined("SMTP_USER"))
			{
				$this->SMTPAuth = true;
				$this->Username = SMTP_USER;
				$this->Password = SMTP_PASSWORD;
				//$this->PluginDir = "";
			}			
			else
			{
				$this->SMTPAuth = false;
				$this->Username = "";
				$this->Password = "";
				//$this->PluginDir = "";
			}			
		}//end of if we are to use SMTP
		else if(defined("SENDMAIL_PATH"))
		{
			$this->Host = "";
			$this->Mailer = "sendmail";
			$this->Sendmail = SENDMAIL_PATH;
			$this->Helo = defined("WEB_SERVER")?WEB_SERVER:"localhost.localdomain";
			$this->SMTPAuth = false;
			$this->Username = "";
			$this->Password = "";
			//$this->PluginDir = "";	

		}//end of if we are to use SENDMAIL
		else
		{
			$this->Host = "";
			$this->Mailer = "mail";
			$this->Helo = defined("WEB_SERVER")?WEB_SERVER:"localhost.localdomain";
			$this->SMTPAuth = false;
			$this->Username = "";
			$this->Password = "";
			//$this->PluginDir = "";
		}
		
		$this->Priority = 3;
		$this->Encoding = "8bit";
		$this->CharSet = "iso-8859-1";
		$this->From = "";
		$this->FromName = "";
		$this->Sender = "";
		$this->Subject = "";
		$this->Body = "";
		$this->AltBody = "";
		$this->WordWrap = 0;
		
		
		
	} //end of mailer constructor

	function send_single($fromaddress, $toaddress, $subject, $body, $headers="") 
	{
		//Note that the $headers variable has been decremented.  It is now defunct.
		//If you need additional headers, we can add them with a different function.
		//The code was searched; we do not use the $headers variable anywhere.

		//get the senders email and possible name
		$this->get_email_parts($fromaddress,$email,$name);
		
		$this->From = $email;	
		$this->FromName = $name;
 $this->Sender = $email;

		//get the recipients email and possible name
		if(ereg(",",$toaddress))
		{			
			$toArray = explode(",",$toaddress);
			while(list($tk,$tv)=each($toArray))
			{
			   //Just a case a blank or space is there.
				$this->get_email_parts($tv,$email,$name);            
				$email=trim($email);
				if($email=="" || $email==" "){
				} else {
				$this->AddAddress($email,$name);
				}
			}
		}
		else if (ereg(";",$toaddress))
		{
			$toArray = explode(";",$toaddress);
			while(list($tk,$tv)=each($toArray))
			{
				$this->get_email_parts($tv,$email,$name);
				$this->AddAddress($email,$name);
			}
		}
		else
		{
			$this->get_email_parts($toaddress,$email,$name);
			$email=trim($email);
			if($email!=""){
 			  $this->AddAddress($email,$name);	
			}
		}
		$this->Subject = $subject;
		$this->Body = $body;

		$retval = $this->Send();
		$this->ClearAllRecipients();
		return $retval;
     
	}//end of function send_single




	function get_email_parts($address_string,&$addr_email,&$addr_name)
	{
		$address_string = trim($address_string);
		if(ereg("(.*)<((.*)(@)(.*))>",$address_string,$matches))
		{		 			
			if($matches[4]=="@")
			{
			 	$addr_email = trim($matches[2]);
				$addr_name = trim($matches[1]);
				return;
			}//end of if the @ sign is where we expect it
		}//end of if there is a match for the angle brackets
		else if( ereg("((.*)(@)(.*)(\((.*)\)))",$address_string,$matches))
		{		
			if($matches[3]=="@")
			{
			 	$addr_email = trim($matches[2])."@".trim($matches[4]);
				$addr_name = trim($matches[6]);
				return;
			}//end of if the @ sign is where we expect it
		}
		else if( ereg("((.*)(@)(.*))",$address_string,$matches))
		{		
        	if($matches[3]=="@")
			{
				
			 	$addr_email = trim($matches[0]);
				$addr_name = "";
				return;
			}//end of if the @ sign is where we expect it
		}
		else
		{
		 	$addr_email = "hide@address.com";
			$addr_name = "nobody";
		}

	}//end of get_email_parts
}//end of class MAILER

?>
Return current item: Epiware Document Management