<?php
 /********************************************* 
    * Publish On : Jan 10th, 2004                * 
    * Scripter   : Hermawan Haryanto             * 
    * Version    : 1.0                           * 
    * License    : GPL (General Public License)  * 
    **********************************************/ 
    require_once('/home/orgatecindia/public_html/imm-india/include/email/PHPMailerAutoload.php');

    function sendmail ($from_name, $from_email, $to_name, $to_email, $subject, $text_message="", $html_message, $attachment="") 
    { 
     $from = "$from_email";
       $to   = "$to_email";
        $main_boundary = "----=_NextPart_".md5(rand());
        $text_boundary = "----=_NextPart_".md5(rand());
        $html_boundary = "----=_NextPart_".md5(rand());
        $headers  = "From: $from_name <$from_email>\n";
        $headers .= "Reply-To: $from\n";
        $headers .= "X-Mailer: Hermawan Haryanto (http://hermawan.com)\n";
        $headers .= "MIME-Version: 1.0\n";
        //$headers .= "Content-Type: multipart/mixed;\n\tboundary=\"$main_boundary\"\n";
        $headers .= "Content-Type: multipart/alternative;\n\tboundary=\"$main_boundary\"\n";
        $message = "\n--$main_boundary\n";
        $message .= "Content-Type: multipart/alternative;\n\tboundary=\"$text_boundary\"\n";
        $message .= "\n--$text_boundary\n";
        $message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\n";
        $message .= "Content-Transfer-Encoding: 7bit\n\n";
        $message .= ($text_message!="")?"$text_message":"Text portion of HTML Email";
        $message .= "\n--$text_boundary\n";
        $message .= "Content-Type: multipart/related;\n\tboundary=\"$html_boundary\"\n";
        $message .= "\n--$html_boundary\n"; 
        $message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n";
        $message .= "Content-Transfer-Encoding: quoted-printable\n\n";
        $message .= str_replace ("=", "=3D", $html_message)."\n";
        
        /*if (isset ($attachment) && $attachment != "" && count ($attachment) >= 1)
        { 
            for ($i=0; $i<count ($attachment); $i++)
            { 
                $attfile = $attachment[$i];
                $file_name = basename ($attfile);
                $fp = fopen ($attfile, "r");
                $fcontent = "";
                while (!feof ($fp))
                { 
                    $fcontent .= fgets ($fp, 1024);
                } 
                $fcontent = chunk_split (base64_encode($fcontent));
                @fclose ($fp);
                $message .= "\n--$html_boundary\n";
                $message .= "Content-Type: application/octetstream\n";
                $message .= "Content-Transfer-Encoding: base64\n";
                $message .= "Content-Disposition: inline; filename=\"$file_name\"\n";
                $message .= "Content-ID: <$file_name>\n\n";
                $message .= $fcontent;
            } 
        }*/ 
        $message .= "\n--$html_boundary--\n";
        $message .= "\n--$text_boundary--\n";
        $message .= "\n--$main_boundary--\n";
       
        // commented by rajiv 
        $result= mail($to,$subject, $message, $headers);
        
        return $result;
    } 
    function sendPHPMail($from_name, $from_email, $to_name, $to_email, $subject, $text_message="", $html_message, $attachment1="",$attachment2="",$attachment3="",$attachment4="",$attachment5="",$replyto="")
	{
				      
				//echo "attachment1= ".$attachment1;
				//echo "<br>attachment2= ". $attachment2;
				//echo"<br>attachment3= ". $attachment3;
				//echo "<br>attachment4= ".$attachment4;
				//echo "<br>attachment5= ".$attachment5;
				//die();
// 			date_default_timezone_set('Etc/UTC');                 
			date_default_timezone_set('Asia/Kolkata');

			$mail = new PHPMailer();       
			$mail->isSMTP();
			$mail->SMTPDebug = 0;
			$mail->Timeout = 60;
			$mail->SMTPAuth = true;                    
			$mail->SMTPSecure = "ssl";        
			
// 			$mail->Host = "mail.iile.in";
            // $mail->Host = "packexindia.com";                  
            $mail->Host = "orgatec-india.com";
			$mail->Port = 465;//587;//465;
// 			$mail->Username = 'admin@orgatec-india.com';
// 			$mail->Password = 'V,W)EYl2,{;p';

			$mail->Username = EMAILID; //$from_email; password :
			$mail->Password = MAILPASSWORD;
 
		  //  $mail->Username = 'packexindia@packexindia.com'; //from email
		  //  $mail->Password = '&hZ^Gtm6uQS5'; //email password
		
		//	$mail-> setFrom($mail->Username,'ANUTEC - International FoodTec India 2021');
			$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);
			}	
			//Set who the message is to be sent to
			
			$emailsExploded = explode(",", $to_email);

			//If the array isn't empty, loop through
			if(!empty($emailsExploded))
			{
    			foreach($emailsExploded as $emailAddress)
    			{
        			$mail->AddAddress(trim($emailAddress),$to_name);
    			}
			} 
			else
			{
    			//This should not be the case.
    			throw new Exception('No emails found!');
			}
			
			$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);
            }
    
 //   print_r($mail);   
  // die();
    //exit;
    		//send the message, check for errors
			if (!$mail->send()) {
				echo 'Mailer Error: ' . $mail->ErrorInfo;
			} else {
				//echo 'Message sent!';
				return '1';
			}
			unset($mail);
	}
	
?>