<?
session_start();
ob_start();
include_once("../dbconnect.php");
for($i=0;$i<count($_POST['customers']);$i++)
{
	$getuemail=mysql_fetch_array(mysql_query("select Email from register where user_id=".$_POST['customers'][$i]));
  $stringids.=$_POST['customers'][$i].",";
   $string.=$getuemail[Email].",";
}
 $get=substr($string,0,-1); 
 $getids=substr($stringids,0,-1);

 $updatecptable=mysql_query("update coupons set coupon_users='".$getids."' where coupon_id=".$_POST[couponlastid]);

    $getcoupondata=mysql_fetch_array(mysql_query("select * from coupons where coupon_id=".$_POST[couponlastid]));
    $message.="Dear Customer
	Your account has been activated with a Discount Coupon Code::".$getcoupondata['coupon_code']."
    This Coupon code is valid for ".$getcoupondata['notimes']." Orders for an amount of ".$getcoupondata['coupon_amt']."\n\n .
	*Note: Coupon Code is Valid only if the Order Amount exceeds".$getcoupondata['coupon_min_amt'].", and its valid from ".        $getcoupondata['coupon_start_date']." to ".$getcoupondata['coupon_end_date']."
	Regards
	www.sirboxusa.com";
	$email_subject = $_POST['emailsubject']; 
	$email_to = "To: ".$get;
	$email_message = $message;
	$email_from=$_POST['mailfrom']; 
    $headers = "From:   ".$email_from;
	mail($email_to,$email_subject,$email_message,$headers); 
	header("location:coupons.php?csent=csent");
?>