<?php
global $connection;
$connection = mysqli_connect( 'localhost', 'webstagi_optoutlevel', 'Vectra@123', 'webstagi_optout_level' );
if ( !$connection ) {
    die( 'Connection failed: ' . mysqli_connect_error() );
}
require( 'constant.php' );
$user_phone = $_POST[ 'phone' ];
date_default_timezone_set( 'Asia/Dubai' );
$udate = date( 'Y-m-d H:i:s' );
$sql = "INSERT INTO level_optout(mobile,udate) values('$user_phone','$udate')";
$result = mysqli_query( $connection, $sql );

if($result) {
	$toEmail = "support@vectramind.com,satish.penjarla@vectramind.com";
	$subject = "UnSubscribe";
	$message = '<html><body>';
	$message .= '<h1 style="color:#f40;">UnSubscribe!</h1>';
	$message .= '<p style="color:#080;font-size:18px;">Phone: '.$user_phone.' </p>';
	$message .= '</body></html>';
	$mailHeaders  = "MIME-Version: 1.0" . "\r\n";
	$mailHeaders .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
	$mailHeaders .= "From: User@vectramind.com". "\r\n";
	
	if(mail($toEmail, $subject, $message, $mailHeaders)) {
		print "<p class='success'>Unsubscribed Successfully</p>";
		} 
		else {
		print "<p class='error'>Unable to send email Please contact admin'</p>";
	}
}
?>