<?php
//Email all members 
			   $sm = "SELECT email from users  ";
			  $acc =  mysqli_query($conn,$sm);
			
			
			if(mysqli_num_rows($acc)>0){
		   
		    $sms_array = array();
				
			while($row = mysqli_fetch_assoc($acc)){
			
		   $sms_array[] = $row["email"];
			}}
			  $send = implode(",",$sms_array);
			  
			  $no = count($sms_array);
			  

$qryApi = mysqli_query($conn,"SELECT * FROM api_setting");
$apidata = mysqli_fetch_array($qryApi);

$apikey = $apidata['APIkey']; //email address()

$qrySt = mysqli_query($conn,"SELECT * FROM settings");
 $Getsit = mysqli_fetch_array($qrySt);
 
 $sitename = $Getsit['sitename'];
 $siteemail = $Getsit['email'];
 $sitephone = $Getsit['mobile'];
 $sitelogo = $Getsit['sitelogo'];
 $siturl = $_SERVER['SERVER_NAME'];
 $sender = $sitename;


  

  
		
		if(isset($_POST['btn'])){
				
		$dest =$_POST['sendto'];
		$mess = $_POST['msg'];
                $subject = $_POST['sub']; 
		
         $brek = explode(",",$dest);
	
	 $nos = count($brek);
	
	 
	 
	foreach($brek as $key => $receiver){
								
						$ins = mysqli_query($conn,"SELECT * FROM users WHERE email='$receiver' ");
							$data = mysqli_fetch_array($ins);
								
							$email = $data['email'];
							
						    $phone = $data['phone'];
  $fname = $data['firstname'];
  $lname = $data['lastname'];
  
							
	
 // echo $receiver; echo "<br>";
   


$from = "$sitename<support@$siturl>"; //the email address from which this is sent
$to = "$receiver"; //the email address you're sending the message to
$subject = "$subject"; //the subject of the message

// To send HTML mail, the Content-type header must be set
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "Return-Path: $sitname<support@$siturl>\r\n";
$headers .= "Organization: $sitname\r\n";
 
// Create email headers
$headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();

$message = "

<html>
<head>
<style>
.table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 50%;
}

td {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}


.button {
  background-color: #008CBA; /* Blue */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  border-radius: 8px;
  cursor: pointer;
  
  -webkit-transition-duration: 0.4s; /* Safari */
  transition-duration: 0.4s;
}

.button:hover {
  background-color: #4CAF50; /* Green */
  color: white;
}

</style>
</head>

<body>

<img src='https://".$siturl."/portal/sitelogo/".$Getsit['sitelogo']."'>

<h3>Dear $fname $lname, </h3>

$mess


<br><br>
<strong>
Thank you for choosing www.$siturl.<br><br>

The Admnistrative TEAM<br>
 $sitename<br>
 $sitephone<br>
 $siteemail<br>
 www.$siturl</strong>
 




</body></html>";

//now mail
$DoMail = mail($to,$subject,$message,$headers);

 }

echo '<div class="alert alert-success">Email Sent Successfully.</div>';	
	}
	
	
?>
	
		
	
