I am trying to create a php script that sends email to specified email id. Script runs successfully without any error but I am not receiving email from database. I am using this script for android app. After filling contact us form from app, when user clicks on SEND, all the details should be received in email. Surprisingly I am seeing the user's entry in database from PhpMyAdmin, however email is not being sent with the data.
I am using following code.
<?php
require('config.php');
date_default_timezone_set('Asia/Kolkata');
$type_of_occasion = trim($_REQUEST['type_occasion']);
$date = trim($_REQUEST['date']);
$content = trim($_REQUEST['content']);
$email = trim($_REQUEST['email']);
if(empty($type_of_occasion) || empty($date) || empty($content) || empty($email)){
echo json_encode(array('status'=>'error','message'=>'Please enter all fields[type,date,content,email of user]'));
exit();
}
$date = date('Y-m-d',strtotime($date));
$query = "INSERT INTO inquiry (email,type_of_occasion,date,content) VALUES ('$email','$type_of_occasion','$date','$content')";
$res = mysqli_query($con,$query);
if($res){
$to = 'abc@email.com';
$message = "Hi,<br>You have one inquiry with below information<br>Email : $email<br>Type Of Occassion : $type_of_occasion<br>Date : $date<br>Details : $content";
$subject = "You have one inquiry";
$header = "From: noreply@xyz.com\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=utf-8\r\n";
$bool = mail($to,$subject,$message,$header);
if($bool){
echo json_encode(array('status'=>'success','message'=>'Inquiry submitted successfully'));
}else{
echo json_encode(array('status'=>'error','message'=>'Error in mail send'));
}
}else{
echo json_encode(array('status'=>'error','message'=>'Error in submitting inquiry'));
exit();
}