<?php

	ini_set("error_log", "php-error.log");


	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 = 'L0g!n@123456';    // 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'];
	$email = "mahesh.miimobile@gmail.com";
	$password = $_REQUEST['password'];

	$message = ("<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <title>WelCome To Mybooster</title>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
	<link href='https://fonts.googleapis.com/css?family=Barlow+Condensed' rel='stylesheet'>
</head>
<body>

<table style='width:700px!important;padding: 0 30px;margin:0 auto;background-color:#f1f1f1;line-height:1.6;color: rgb(19, 18, 18);box-sizing:border-box; font-family: Barlow Condensed, sans-serif;'>
    <thead>
    <tr>
        <td style='padding:10px 0 10px;text-align:left'>
            <h1><a href='https://mybooster.biz/' target='_blank'><img src='http://localhost/MyBooster/images/mybooster-logo.png' alt='MyBooster' width='140' /></a></h1>
        </td>
        <td style='padding:10px 0 10px;text-align:right'>
            <time style='font-weight:bold'>" . date("d-m-Y H:i:s")  . "</time>
        </td>
    </tr>
    </thead>

    <tbody>
    <tr>
        <td colspan='4'>

            <table style='background-color:#fff;width: 100%' >
                <tbody>
                <th style='padding:18px 30px 28px;background-image: linear-gradient(to right top, #ee2f34, #e85272, #cc58ac, #b33ea9, #9524a9);padding-right:0;border-radius:8px 0 0 0;'><h1 style='line-height:1.18;font-size:24px;padding:0 30px;color:white;margin:0;text-align:center'>Welcome To MyBooster</h1></th>

                <tr>
                    <td style='padding:15px;width: 100%'>
                        <p style='margin:0;padding:3px 0;font-size:16px;line-height:1.42'>Use mentioned Member ID and Password to sign in your MyBooster account.</p><br>
                        <p style='margin:0;padding:5px 0;font-size:16px;line-height:1.42'>Hi<b>  " .  $name   . "</b>, </p><br>
                        <p style='margin:0;padding:3px 0;font-size:16px;line-height:1.42'><b>Welcome to MyBooster!</b> evolve with purity. </p>
                        <p style='margin:0;padding:15px 0 0 0;font-size:16px;line-height:1.42'>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><br>
                        <p style='margin:0;padding:3px 0 0 0;font-size:16px;line-height:1.42'> You made an excellent choice by joining mybooster.biz. </p><br>
                        <p style='margin:0;padding:5px 0 0 0;font-size:18px;line-height:1.42'>Member ID: <b>" . $referID  . "</b></p><br>
                        <p style='margin:0;padding:5px 0 0 0;font-size:18px;line-height:1.42'>Password: <b>"  . $password . "</b></p><br>
                        <p style='margin:0;font-size:16px;line-height:4'> Thanks, </p> 
                        <p style='margin:0;font-size:16px;line-height:1'><b>MyBooster</b> Support Team </p><br>
                        <p style='margin:0;padding:15px 0 0 0;font-size:12px;line-height:1.42'>For Instructions on how yo buy products on MYBOOSTER Platform, See Our Support Desk.</p><br>
                    </td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    </tbody>
    <tfoot>
    <tr>
        <td colspan='4' style='padding:24px 0px 38px'>
            <table style='color:grey;font-size:13px'>
                <tbody><tr>
                    <td style='border-collapse:collapse;vertical-align:baseline;text-align:left;padding:0 0 4px'><strong>Support</strong></td>
                </tr>
                <tr>
                    <td style='border-collapse:collapse;vertical-align:baseline;text-align:left;padding:0 0 14px'>
                        <p style='margin:0;float:left;max-width:100%'>
                            <span style='display:inline-block;margin:0 5px 0 0;font-size:14px'><b>Website: </b><a href='https://www.mybooster.biz' style='color:#f79300;text-decoration:none' target='_blank'>https://www.mybooster.biz</a></span>
                            <span style='display:inline-block;margin:0 5px 0 0;font-size:14px'><b>Email:</b> <a href='mailto:info@mybooster.biz' style='color:#f79300;text-decoration:none'>info@mybooster.biz</a></span>
                        </p>
                    </td>
                </tr>
                <tr>
                    <td style='border-collapse:collapse;vertical-align:baseline;text-align:left'><p style='margin:0;width:100%;font-size:14px'>Please do not reply to this e-mail. Please note that replies to this email address are not monitored, therefore we will not be able to reply to you.</p></td>
                </tr>
                <tr>
                    <td style='border-collapse:collapse;vertical-align:baseline;text-align:left'>
                        <ul style='list-style:none;padding:16px 0 0;margin:21px 0 0;border-top:1px solid rgb(178,178,178)'>
                            <li style='margin:0;float:left'><a href='#' style='color:grey;text-decoration:none' target='_blank'>Terms&amp;Conditions</a></li>
                            <li style='margin:0 0 0 15px;float:left'><a href='#' style='color:grey;text-decoration:none' target='_blank'>Privacy policy</a></li>
                            <li style='margin:0 0 0 15px;float:right'><a href='https://mybooster.biz' style='color:grey;text-decoration:none' target='_blank'>https://www.mybooster.biz</a></li>
                        </ul>
                    </td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    </tfoot>
</table>

</body>
</html>");

$sub = "MyBooster: Welcome";

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

echo $response;
?>