Saturday, 10 March 2018

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

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...