Contact form wont send

Hi, my contact form wont send to my email. Anything I’m missing? Website is reesecodes.com/contact.php and the PHP script is this:

[code]

<?php echo "
";
print_r($_POST);  
echo "
"; exit; $to = "ericreese20@gmail.com"; $from = $_POST['email']; $name = $_POST['name']; $message = $_POST['message']; $subject = "You have a message sent from your site"; $body = $name." from ".$from." says: ".$message; mail($to, $subject, $body); ?>[/code]
1 Like

Your debugging is killing you. The exit (line 4 right before the $to is assigned a value) will prevent anything further down from executing.

3 Likes

Thankk you, fixed it. This is why I usually stick to front end development

1 Like

Oh wait, another error. When looking at my email, the content is

from says:

its not grabbing the variable data for some reason?

I’m worried it has to do with my ajax

this is the validate.js code

jQuery.validator.addMethod('answercheck', function (value, element) { return this.optional(element) || /^\bcat\b$/.test(value); }, "Please try again"); jQuery.validator.addMethod('answercheck', function (value, element) { return this.optional(element) || /^\bcat\b$/.test(value); }, "Please try again"); // validate contact form $(function() { $('#contact').validate({ rules: { name: { required: true }, email: { required: true, email: true }, message: { required: true }, answer: { required: true, answercheck: true } }, messages: { name: { required: "Please enter your name." }, email: { required: "Please enter your e-mail." }, message: { required: "Please write a message" }, answer: { required: "Sorry, wrong answer!" } }, submitHandler: function(form) { $(form).ajaxSubmit({ type:"POST", data: $(form).serialize(), url:"scripts/contactform.php", success: function() { $('#contact :input').attr('disabled', 'disabled'); $('#contact').fadeTo( "fast", 0.15, function() { $(this).find(':input').attr('disabled', 'disabled'); $(this).find('label').css('cursor','default'); $('#error').fadeIn(); }); }, error: function() { $('#contact').fadeTo( "fast", 0.15, function() { $('#success').fadeIn(); }); } }); } }); });

Is your contactform.php the one from post 1? You need to, in your PHP, json_encode the results, I believe. It works a bit different when you use Ajax, rather than straight PHP.

Also, what’s this?

$(this).find(':input').attr('disabled', 'disabled');

:input?

Also you do know that .success() is not the same as your PHP script deeming it valid / passing the checks in PHP, right?

I just decided to delete the ajax and go php only so it works nowf

1 Like

Does your real code actually validate the inputs or can anything be entered into those variables so as to allow your page to be used to send spam?

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.