Php Script Sending Mails But Not Showing Form Data
Solution 1:
Your content is in a variable called $message
. You pass one called $body
to mail()
. If you had error reporting turned on php would have reported this to you.
$success = mail($email_to, $subject, $mesage, 'From: <'.$email_from.'>');
FYI, using @
to suppress errors is a bad practice. It only makes debugging more difficult and is not the proper way to handle potential errors.
Solution 2:
The "@" symbol prior to a function in php will suppress any error messages. It is best to not use those until your application is ready for deployment. I recommending removing those until everything is working as you would like it.
I recommend validating user input prior to processing it. There are several scripts online that you can use for the same.
To fix your current issue use:
$success = @mail($email_to, $subject, $message, 'From: <'.$email_from.'>');
Solution 3:
Note Read the comment in the answer. in there i explain, why you were able to sent mail. and not the other value
Like
Change these line.
Note use input type
instead of button
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
To these
<inputtype="submit" name="submit"class="btn btn-primary btn-lg" required="required">
Comment You are able to sent the mail
cause you hardcoded it in your script
Like on this line
$email_to = 'vishal@gmail.com';//replace with your email
Your other value depend on your form. These value. You are not getting these value through your form.
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
Comment Two dont use @
in production. as it supress the error. And error message are important during production.
Comment three Always sanitaize or validate user input. for security purpose.
Solution 4:
Step to solving errors:
1) Check these variables are storing data:
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
by echo one by one.
2) Then pass them to $body
variable.
3) Use proper header with content type and from and reply tags.
Try this one like:
$headers= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers`enter code here`$headers.= 'To:' . "\r\n";
$headers.= 'From: Admin<youremail@email.com>' . "\r\n";
// Mail it
mail($to, $subject, $body, $headers);
Solution 5:
None of the above things worked for me. There was just a problem in underlying javascript... it was not able to get the data, serializing the form worked well for me
// Contact form
var form = $('#main-contact-form');
var data = $form.serialize()
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
type: "POST",
dataType: "json",
data: data,
url: $(this).attr('action'),
beforeSend: function(){
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
}
}).done(function(data){
form_status.html('<p class="text-success">' + data.message + '</p>').delay(3000).fadeOut();
});
});
Post a Comment for "Php Script Sending Mails But Not Showing Form Data"