<?php
@require_once 'mail_master/PHPMailerAutoload.php';
@set_time_limit(0);

$destination = "logs/faic_mail" . date('Y-m-d') . ".log";

$json = file_get_contents('php://input');
$obj = json_decode($json);

//error_log("\n" . date('Y-m-d H:i:s') . " Incoming Request :\n $json ", 3, $destination);

$api_key = $obj->{'api_key'};
$user_name = $obj->{'user_name'};
$mail_subject = "Finance Update";
$send_to = $obj->{'send_to'};


if($api_key=='YTc4YWY3ZWVlZWViODU3YTY5ODUzNTA4ZGU3YzVhYzM1NTdjNjM1MWEyYzA1ODU1ZDhlqA12AjkP0qNTc4ZjU3N2QwMDVmMw==')
{
    global $error;
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com'; //
    $mail->Port = 465;
    $mail->Username = "finance@sheriakiganjani.or.tz";
    $mail->Password = "wyublqszsjdjsaxb";
    $mail->SetFrom("finance@sheriakiganjani.or.tz", "Finance");
    $mail->Subject = $mail_subject;
    $mail->IsHTML(true); 
    $mail->Body    = "Greetings <br/>Hope this e-mail finds you well.<br/> This is to notify you that a new request has been submited.<br/>Kindly proceed to Finance Portal for further processes.<br/>Best Of Regards";
    $mail->AddAddress($send_to);
    if (!$mail->Send()) {
        $error = 'Mail error: ' . $mail->ErrorInfo;
        $response=array(
        "status"=>"202",
        "statusDesc"=>$error       
    );
    $response=json_encode($response);
    //error_log("\n" . date('Y-m-d H:i:s') . " Response :\n $response ", 3, $destination);
    print_r($response);
    die();
    } else {
        
        $response=array(
        "status"=>"200",
        "statusDesc"=>"Success"        
    );
    $response=json_encode($response);
    //error_log("\n" . date('Y-m-d H:i:s') . " Response :\n $response ", 3, $destination);
    print_r($response);
    die(); 
        
    }
}
else
{
    $response=array(
        "status"=>"201",
        "statusDesc"=>"Invalid API KEY"        
    );
    $response=json_encode($response);
    //error_log("\n" . date('Y-m-d H:i:s') . " Response :\n $response ", 3, $destination);
    print_r($response);
    die(); 
}



