<?php include("includes/db_config.php"); 
if($_SERVER['REQUEST_METHOD']=='POST'){
    extract($_POST);
    date_default_timezone_set('Asia/Kolkata');
    $created_at = date( 'Y-m-d h:i:s A', time () );    
    $payment_status="completed";
    $statuss=1;
$sql_pay ="UPDATE  user_payment SET payment_method='$payment_method',pay_status='$payment_status',payable_status='$statuss',created_date='$created_at' WHERE order_id='".$order_id."'"; 
if  (mysqli_query($conn, $sql_pay))
{  $sql_pet="select * from user_payment where order_id='".$order_id."'";
    $relt_ptm = mysqli_query($conn, $sql_pet);
    $res_pt= mysqli_fetch_array($relt_ptm);
    $id=$res_pt['id'];
    $user_id=$res_pt['user_id'];
    $order_id=$res_pt['order_id'];
    $cart_id=$res_pt['cart_id'];
     $rid = explode(",",$cart_id);
    foreach($rid as $pm_id){
     $stat="1";
     $statuss="0";
     $sql_paytmss ="UPDATE  addto_cart SET payment_status='$stat',invoice_id='$statuss' WHERE id='".$pm_id."'"; 
     $result_ptmss=mysqli_query($conn,$sql_paytmss) or die(mysqli_error());
     }
    
     $sqqq="select * from user_profile where id=".$user_id;
    $sql1=mysqli_query($conn, $sqqq);
    $row1=mysqli_fetch_array($sql1);
    $total_price = $res_pt['total_price'];
    $email = $row1['email'];
    $name = $row1['fname'];
    $date = date("d-m-Y");
    $from_team = "Orange Groceries";
    $from_website = "https://orangegroceries.com/index.php";
    $from_email = "support@orangegroceries.com";
    $subject = "Order Placed With Orange Groceries";
    $to = $email;
    $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi $name,
                                    </span> 
                                    <br/>
                                    Welcome to <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $from_team</span>, Your Order Placed with RS.$total_price , Pay On Delivery <br/> Thankyou!!!
                                </p>
                                <br/><br/><br/><br/>
                                <div style='width: 100%; background-color: $footer_background_color; color: $footer_text_color; font-family: $footer_font_family; font-size: $footer_font_size; padding-top: 30px; padding-bottom: 30px;'>
                                    Thanks And Regards
                                    <br/>
                                    <span style='color: white;'>$from_website</span>
                                </div>
                            </div>
                        </center>
                    </body>
                </html>";
 $headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    // Write your information where you send this mail FROM
$headers .= 'From: ' .$from_team. ' <' .$from_email. '>' . "\r\n";
    // If Required
   // $headers .= 'Cc: ' .$cc. "\r\n";
    // Chechking Mail Sent or Not;
  if (! mail($to,$subject,$message,$headers)) {
       echo "Problem in sending email!";
         echo "Mailer Error: " . $mail->ErrorInfo;

    } else {
   $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi Team,
                                    </span> 
                                    <br/>
                                    Order Placed By <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $name</span>, with RS.$total_price , Payment method Is Cash On Delivery ..<br/> !!!
                                </p>
                            </div>
                        </center>
                    </body>
                </html>";                
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    // Write your information where you send this mail FROM
$headers .= 'From: ' .$from_team. ' <' .$from_email. '>' . "\r\n";
    // If Required
   // $headers .= 'Cc: ' .$cc. "\r\n";
    // Chechking Mail Sent or Not;
  if (! mail("support@orangegroceries.com","Order Placed By" .$name,$message,$headers)) {
        echo "Problem in sending email!";
         echo "Mailer Error: " . $mail->ErrorInfo;

    } else {
               echo "email sended!";

    }
}
//include("paymail_android.php"); 

    $response['id']=$id; 
    $response['status']=1;
}else{
$response['status']=0;
}
	echo json_encode($response);
	mysqli_close($conn);
}

?>