Saturday 8 June 2019

php - Mail function sending blank values

I am trying to send an email to user account using php mail() function.The mail is sent successfully but the issue is that it is sending me blank emails with no values in them! The code for the contact page that sends the email is as follows:-



























and sendemail.php page code is as follows:




header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);

$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$subject = "An enquiry sir";
$message = @trim(stripslashes($_POST['message']));


$email_from = $email;
$email_to = 'email@email.com';

echo $body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;

$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

echo json_encode($status);
die;

?>


Why is the output I get blank in my email id, for example:




Name:



Email:




Subject:



Message:




P.N: I am using here a nova template theme.



The form is being submitted via AJAX using the following JavaScript:



var form = $('.contact-form');

form.submit(function () {
$this = $(this);
$.post($(this).attr('action'), function(data) {
$this.prev().text(data.message).fadeIn().delay(3000).fade‌​Out();
},'json');
return false;
});

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...