<?php

/*	b2b.class.mailer.php	*/

//require_once('/home/solarexplosives/public_html/B2B/classes/class.phpmailer.php');
if(!file_exists('./classes/class.phpmailer.php')){
	require_once('./../../../classes/class.phpmailer.php');	
}
else{
	require_once('./classes/class.phpmailer.php');
}

class solarMailer extends PHPMailer {
// Set default variables for all new objects


public $From     	= "b2b.solarexplosives@gmail.com";
public $FromName 	= 'Admin@b2b.SolarExplosives';

public $Host		= "ssl://smtp.gmail.com";		// "smtp1.site.com;smtp2.site.com"; 
public $Port		= "465";
public $Mailer		= 'smtp';						// Alternative to IsSMTP()
public $Password	= 'ExploSolar@2016';

public $WordWrap	= 0;
public $SMTPAuth	= true;

public $AddressBCC	= '';
public $AddressReplyTo	= '';

public function __construct($debug = 1){
    $this->Sender = $this->From;
    $this->Username = $this->From;
    $this->SMTPDebug = $debug;		// 0:No Debug Info, 1:Minimal Debug Info, 2:Verbose Debug Info
}

public function sendSolarMail($AddressTo, $Subject, $Body, $AddressCC=NULL, $AddressBCC=NULL, $IsHtml=False) {
	$success = FALSE;
	//return $success;

	if ($this->setAddress('AddAddress', $AddressTo)) {
		$this->setAddress('AddCC', $AddressCC);
		$this->setAddress('AddBCC', $AddressBCC);

		$this->Subject = $Subject;
		$this->Body = $Body;
		//if($attachmentpath!=NULL){
		//$this->AddAttachment($attachmentpath);      // attachment
		//}

		$success = $this->Send();
		if (!$success) {
			$alertMsg = "$Subject e-mail is not sent." . '\n' . "EMailId: $AddressTo." . '\n' . "Mailer Error: $this->ErrorInfo";
			echo "<script> alert('$alertMsg'); </script>";
		}
	}
	return $success;
}

public function sendSolarMailPOApproval($AddressTo, $Subject, $Body, $AddressCC=NULL, $attachment) {
	$success = FALSE;
	//return $success;

	if ($this->setAddress('AddAddress', $AddressTo)) {
		$this->setAddress('AddCC', $AddressCC);

		$this->Subject = $Subject;
		$this->Body = $Body;
		if($attachment!=NULL){
			for($i=0; $i<sizeof($attachment); $i++){
				
			//	$p=$attachment[$i];
				//$path='/var/zpanel/hostdata/solarexp/public_html/b2b_solarexplosives_com/upload/re11PDF/PO/';
				//$path=$path.$p;
				$path=$attachment[$i];
				$this->AddAttachment($path);
			}
		}

		$success = $this->Send();
		if (!$success) {
			$alertMsg = "$Subject e-mail is not sent." . '\n' . "EMailId: $AddressTo." . '\n' . "Mailer Error: $this->ErrorInfo";
			echo "<script> alert('$alertMsg'); </script>";
		}
	}
	return $success;
}


protected function setAddress($AddressMethod, $AddressString) {
// $AddressString: ; delimited multiple To Addresses, each with Address followed by optional , delimited Name
// eg "dashgandhi@yahoo.com,Dasharath Gandhi;dashgandhi@gmail.com;dashgandhi@outlook.com,Dasharath"
	if (empty($AddressString)) return FALSE;

	$AddressArr = explode(';',$AddressString);
	foreach ($AddressArr as $AddressRow) {
		$AddressRowExplode = array_map('trim', explode(',', $AddressRow));
		$Address = $AddressRowExplode[0];
		$Name = (sizeof($AddressRowExplode)>1 ? $AddressRowExplode[1] : '');
		$this->{$AddressMethod}($Address, $Name);
	}
	return TRUE;
}

}


?>
