<?php


	require_once __DIR__.'/../lib/PHPMailer/src/PHPMailer.php';
	require_once __DIR__.'/../lib/PHPMailer/src/SMTP.php';
	require_once __DIR__.'/../lib/PHPMailer/src/Exception.php';

	function sendPHPMailer($email, $sub, $message, $attachments=null){

		$mail = new PHPMailer\PHPMailer\PHPMailer(true); // Passing `true` enables exceptions
		try {
		    //Server settings
		    $mail->SMTPDebug = 0;                                 // Enable verbose debug output
		    $mail->isSMTP();                                      // Set mailer to use SMTP
		    $mail->Host = 'mail.mybooster.biz';  // Specify main and backup SMTP servers
		    $mail->SMTPAuth = true;                               // Enable SMTP authentication
		    $mail->Username = 'info@mybooster.biz';                 // SMTP username
		    $mail->Password = '%4i?TrvaNt1e';    // SMTP password
		    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
		    $mail->Port = 465;                                    // TCP port to connect to

		    //Recipients
		    $mail->setFrom('info@mybooster.biz', 'MyBooster Team');
		    $emailIDs = explode(",", $email);
			   foreach ($emailIDs as $email) {
			   		 $mail->addAddress($email, '');
			   }
		           // Name is optional
		    // $mail->addReplyTo('info@example.com', 'Information');
		    // $mail->addCC('cc@example.com');
		    // $mail->addBCC('bcc@example.com');

		    //Attachments
		   	if(!is_null($attachments)){
		   		$attachments = explode(",", $attachments);
			   foreach ($attachments as $attachment) {
			   		 $mail->addAttachment($attachment, '');
			   }
		   	}

		    //Content
		    $mail->isHTML(true);                                  // Set email format to HTML
		    $mail->Subject = $sub;
		    $mail->Body    = $message;
		    //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

		    if($mail->send()){

		    	$result['status'] = 1;

		    	$result['message'] = "Email has been sent successfully.";
		    }else{
		    	$result['status'] = 0;

		    	$result['message'] = "Error while sending email.";
		    }
		   
		} catch (Exception $e) {
				$result['status'] = 0;

		    	$result['message'] = 'Message could not be sent. Mailer Error: '. $mail->ErrorInfo;

		    //echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
		}

		return json_encode($result);

	}

$user_agent = $_REQUEST['HTTP_USER_AGENT'];

function getOS() { 

    global $user_agent;

    $os_platform  = "Unknown OS Platform";

    $os_array     = array(
                          '/windows nt 10/i'      =>  'Windows 10',
                          '/windows nt 6.3/i'     =>  'Windows 8.1',
                          '/windows nt 6.2/i'     =>  'Windows 8',
                          '/windows nt 6.1/i'     =>  'Windows 7',
                          '/windows nt 6.0/i'     =>  'Windows Vista',
                          '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
                          '/windows nt 5.1/i'     =>  'Windows XP',
                          '/windows xp/i'         =>  'Windows XP',
                          '/windows nt 5.0/i'     =>  'Windows 2000',
                          '/windows me/i'         =>  'Windows ME',
                          '/win98/i'              =>  'Windows 98',
                          '/win95/i'              =>  'Windows 95',
                          '/win16/i'              =>  'Windows 3.11',
                          '/macintosh|mac os x/i' =>  'Mac OS X',
                          '/mac_powerpc/i'        =>  'Mac OS 9',
                          '/linux/i'              =>  'Linux',
                          '/ubuntu/i'             =>  'Ubuntu',
                          '/iphone/i'             =>  'iPhone',
                          '/ipod/i'               =>  'iPod',
                          '/ipad/i'               =>  'iPad',
                          '/android/i'            =>  'Android',
                          '/blackberry/i'         =>  'BlackBerry',
                          '/webos/i'              =>  'Mobile'
                    );

    foreach ($os_array as $regex => $value)
        if (preg_match($regex, $user_agent))
            $os_platform = $value;

    return $os_platform;
}

function getBrowser() {

    global $user_agent;

    $browser        = "Unknown Browser";

    $browser_array = array(
                            '/msie/i'      => 'Internet Explorer',
                            '/firefox/i'   => 'Firefox',
                            '/safari/i'    => 'Safari',
                            '/chrome/i'    => 'Chrome',
                            '/edge/i'      => 'Edge',
                            '/opera/i'     => 'Opera',
                            '/netscape/i'  => 'Netscape',
                            '/maxthon/i'   => 'Maxthon',
                            '/konqueror/i' => 'Konqueror',
                            '/mobile/i'    => 'Handheld Browser'
                     );

    foreach ($browser_array as $regex => $value)
        if (preg_match($regex, $user_agent))
            $browser = $value;

    return $browser;
}


	$user_os        = getOS();
	$user_browser   = getBrowser();

	$name = ucwords($_REQUEST['receiverName']);
	$referID = $_REQUEST['receiverID'];
	$email = $_REQUEST['receiverMailID'];

	$message = ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Welcome MyBooster</title>
    
    
  </head>
  <body style="-webkit-text-size-adjust: none; box-sizing: border-box; color: #74787E; font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; height: 100%; line-height: 1.4; margin: 0; width: 100% !important;" bgcolor="#ffd1d1">
  <style type="text/css">
		body {
		width: 100% !important; height: 100%; margin: 0; line-height: 1.4; background-color: #F2F4F6; color: #74787E; -webkit-text-size-adjust: none;
		}
		@media only screen and (max-width: 600px) {
		  .email-body_inner {
			width: 100% !important;
		  }
		  .email-footer {
			width: 100% !important;
		  }
		}
		@media only screen and (max-width: 500px) {
		  .button {
			width: 100% !important;
		  }
		}
  </style>
    <span class="preheader" style="box-sizing: border-box; display: none !important; font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 1px; line-height: 1px; max-height: 0; max-width: 0; mso-hide: all; opacity: 0; overflow: hidden; visibility: hidden;">Use mentioned Member ID to sign in your MyBooster account.</span>
    


   <table width="100%" border="0" cellspacing="0" cellpadding="0" style="min-width: 320px;"><tr><td align="center" bgcolor="#ffd1d1">  
    <table border="0" cellspacing="0" cellpadding="0" class="table_width_100" width="100%" style="max-width: 680px; min-width: 300px;">
        <tr><td>
    	<!-- padding --><div style="height: 40px; line-height: 40px; font-size: 10px;"></div>
    	</td></tr>
    
    
    	<!--content 1 -->
        
    	<tr><td align="center" bgcolor="#fbfcfd">
    		<table width="90%" border="0" cellspacing="0" cellpadding="0">
			<tr><td align="center">
    				<div style="line-height: 24px;">
    					<a href="#" target="_blank" style="color: #596167; font-family: Arial, Helvetica, sans-serif; font-size: 13px;">
    						<font face="Arial, Helvetica, sans-seri; font-size: 13px;" size="3" color="#596167">
    							<img src="http://localhost/MyBooster/images/mybooster-logo2.png" alt="Mybooster" border="0" style="display: block;height:90px;" />
							</font>
						</a>
    				</div>
    				<!-- padding -->
    		 </td></tr>
			 <tr><td align="center">
                    <!-- padding --><div style="height: 20px; line-height: 20px; font-size: 10px;"></div>
                        <font face="Arial, Helvetica, sans-serif" size="5" color="#333334" style="font-size: 34px;">
                        <span style="font-family: Arial, Helvetica, sans-serif; font-size: 34px; color: #333334;">
                            <h3>Welcome ' .  $name . ' </h3>
                        </span></font> 
                    <!-- padding -->
               </td></tr>
     		   <tr><td align="center">
                    <font face="Arial, Helvetica, sans-serif" size="5" color="#333334" style="font-size: 34px;">
                    <span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; color: #333334;">
                        
                        <p align="justify">We at MyBooster are truly delighted to have you on board. 
                        We know the value of hard-earned money, and we guarantee absolute peace of mind on your purchases.</p>
                         <p align="justify">
                        Ready to start? Login to your MyBooster Account using Member ID: '. $referID  .'</p>
                     </span></font>
                <!-- padding --><div style="height: 10px; line-height: 10px; font-size: 10px;"></div>
                </td></tr>

			
                <tr><td align="justify">
                        <font face="Arial, Helvetica, sans-serif" size="5" color="#333334" style="font-size: 28px;">
                        <span style="font-family: Arial, Helvetica, sans-serif; font-size: 20px; color: #333334;">You made an excellent choice by joining <a href ="http://localhost/MyBooster/" target="_blank" >localhost/MyBooster</a>
                        </span></font>
                    <!-- padding --><div style="height: 40px; line-height: 40px; font-size: 10px;"></div>
                </td></tr>


				<tr><td align="right">
						<font face="Arial, Helvetica, sans-serif" size="5" color="#333334" style="font-size: 34px;">
						<span style="font-family: Arial, Helvetica, sans-serif; font-size: 20px; color: #333334;">
							
						  <p><Strong><span align="left">Thank You,</strong><br/>
										   Team MyBooster</h3> </p>


						</span></font>
					<!-- padding -->
				</td></tr>

				
				<tr><td align="left">
					<div style="line-height: 20px;">
						<font face="Arial, Helvetica, sans-serif" size="5" color="#333334" style="font-size: 34px;">
						<span style="font-family: Arial, Helvetica, sans-serif; font-size: 24px; color: #333334;">
							<h5>For more help</h5><h6>For instructions on how to buy products on mybooster platform, see our support desk.</h6>
							Email us: <a href="mailto:info@mybooster.biz">info@mybooster.biz</a>
						</span></font>
					</div>
				</td></tr>
				<tr><td align="center">
					<div style="line-height: 24px;">
						<font face="Arial, Helvetica, sans-serif" size="4" color="#333334" style="font-size: 15px;">
						<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; color: #333334;">
						This is an automated email, please do not reply
							
						</span></font>
					</div>
					<!-- padding --><div style="height: 40px; line-height: 40px; font-size: 10px;"></div>
				</td></tr>
    		
	   		</table>		
    	</td></tr>
    	<!--content 1 END-->
    
		<!--footer -->
    	<tr><td class="iage_footer" align="center">
   		
    		<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#fbfcfd">
    			<tr><td align="center">
    				<font face="Arial, Helvetica, sans-serif" size="3" color="#333334" style="font-size: 13px;">
    				<span style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #333334;">
    					<p> <strong>MyBooster</strong> &copy; 2018. All Rights Reserved.</p>
    				</span></font>				
    			</td></tr>			
    		 </table>
			 <tr><td>
				<!-- padding --><div style="height: 40px; line-height: 40px; font-size: 10px;"></div>
			 </td></tr>
    	</td></tr>

</td></tr>
</table></table>
  </body>
</html>');

$sub = "MyBooster: Welcome";

$response = sendPHPMailer($email, $sub, $message);

echo $response;