<?php
	
ini_set('max_execution_time', 1200); 

function sendPHPMail($from_name, $from_email, $to_name, $to_email, $subject, $text_message, $html_message, $attachment1="", $attachment2="", $attachment3="", $attachment4="", $attachment5="", $replyto="")
{
				       
	$emailsExploded = explode(",", $to_email);
	      
	//date_default_timezone_set('Etc/UTC');
	date_default_timezone_set("Asia/Kolkata");   
	
	require_once(PHPMAILER_PATH.'PHPMailerAutoload.php');
	
	$mail = new PHPMailer();
	//Tell PHPMailer to use SMTP
	$mail->isSMTP();
// 	$mail->SMTPDebug = 1;
	$mail->Timeout = 240;			
	//Ask for HTML-friendly debug output
	//$mail->Debugoutput = 'html';
	$mail->CharSet = 'UTF-8';
	//Set the hostname of the mail server
	$mail-> Host = 'mail.polymertubing.in';
	$mail->SMTPSecure = "ssl";     
	//Set the SMTP port number - likely to be 25, 465 or 587
	$mail->Port = 465;
	//Whether to use SMTP authentication
	$mail->SMTPAuth = true;
	
	$mail->Priority = 1;
	//Username to use for SMTP authentication
	$mail->Username = 'admin@creditsoftware.polymertubing.in'; // $from_email; //$from_email;
	//Password to use for SMTP authentication
// 	$mail->Password = 'i?!*I5^33[Zs';
	$mail->Password = 'g3){3crr}iHu';
	
	//Set who the message is to be sent from
	$mail-> setFrom($mail->Username, $from_name);
	//Set an alternative reply-to address
	if ($replyto!='')
	{
		$mail-> addReplyTo($replyto, $from_name);
	}
	else
	{			
		$mail-> addReplyTo($from_email, $from_name);
	}	
	
	$emailsExploded = explode(",", $to_email);

	if(!empty($emailsExploded))
	{
		foreach($emailsExploded as $emailAddress)
		{
		    // $emailAddress = 'rajivatre@gmail.com';
			$mail->AddAddress(trim($emailAddress),$to_name);
		
	        $mail-> Subject = $subject;
			$mail->isHTML(true);                                  // Set email format to HTML
            $mail->msgHTML($html_message); 
			$mail->AltBody = $text_message;
			
			if ($attachment1!='')
             {
                $mail->addAttachment($attachment1);
             }
             if ($attachment2!='')
             {
                $mail->addAttachment($attachment2);
             }
             if ($attachment3!='')
             {
                $mail->addAttachment($attachment3);
             }
             if ($attachment4!='')
             {
                $mail->addAttachment($attachment4);
             }
             if ($attachment5!='')
             {
                $mail->addAttachment($attachment5);
             }
		}
		if (!$mail->send())
		{
			$error_message = $mail->ErrorInfo;
			
			throw new Exception("Email has been not sent due to : ".$error_message);
			
			return false;
		}
		else
		{
		    return true;	
		}
		unset($mail);
	    
	} 
	else
	{
		//This should not be the case.
		throw new Exception('No emails found!');
	}
			
	}
	
   