Jump to content

simple contact form not working...


izzi81

Recommended Posts

Hi, I'm hoping someone can help me out with this. I bought an html template to use for my website. I'm self taught, and fairly happy to potter away tweaking css and html. When it comes to php, I know very little and generally just use ready-to-go scripts. This template came with a ready to go contact form, but it's not working. I got in touch with the template developers but they are quite slow at responding (this is the last thing I need to get working to launch the site, which I need to do ASAP) and also to help with the problem they asked for ftp access. Which seems a bit extreme to me to take a look at a script problem!

 

What is confusing me is that in the code on the page, the script is not called anywhere. I don't know a whole lot about php but I'm pretty sure they need to be called in order to do anything? I tried calling it myself, and that didn't fix the issue, so now I'm a bit stuck. The php code is:

<?php

 // ++++++++++++++++++++++++++++++++++++
error_reporting(0);

  
 // configuration

$email_it_to = "(my email in here)";

$error_message = "Please complete the form first";

  
  
if(!isset($rnd) || !isset($name) || !isset($email) || !isset($subject) || !isset($body)) {
	echo $error_message;
    die();
}
	$email_from = $email;
	$email_subject = "Contact Form: ".stripslashes($subject);
	$email_message = "Message submitted by '".stripslashes($name);
	$email_message .="' on ".date("d/m/Y")." at ".date("H:i")."\n\n";
	$email_message .= stripslashes($body);

	$headers = 'From: '.$email_from."\r\n" .
   'Reply-To: '.$email_from."\r\n" .
   'X-Mailer: PHP/' . phpversion();

	mail($email_it_to, $email_subject, $email_message, $headers);

	die();
?>

and is saved as contactform.php

 

The code on the index page for the form is this:

<!-- form -->
                		<div id="contactWrapper">
                    		<form id="contactform">
                
                        		 <div class="stage">
                        		<label for="name"><small>Name: <em>*</em></small></label>
                        		<input type="text" name="contactname" id="name" value="" class="required" aria-required="true" />
               					 </div>
    
                        		<div class="stage">
                            		<label for="email"><small>Email: <em>*</em></small></label>
                            		<input type="text" name="email" id="email" value="" class="required email" aria-required="true" />
                        		</div>
    
                        		<div class="stage">
                            		<label for="subject"><small>Subject: <em>*</em></small></label>
                            		<input type="text" name="subject" id="subject" value="" class="required" aria-required="true" />
                        		</div>
    
                        		<div class="stage">
                           		 	<label for="body"><small>Message: <em>*</em></small></label>
                            		<textarea rows="8" name="body" id="body" class="required"  aria-required="true"></textarea>
                        		</div>
        
                        		<input type="button" value="Send Message" id="submit" onClick="return check_values();">
                    		</form>
                		</div><!-- /form -->

On the site the form acts as if something has been sent, but nothing has. I would be so grateful if someone could tell me what's going on!

(btw I did put my email address in the (my email here) section - at least I know to do that much!)

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/285587-simple-contact-form-not-working/
Share on other sites

change

 

<form id="contactform">

 

to <form id="contactform" method = 'POST' action='contactform.php'>

 

( this is given that the index file and php file are in the same directory)

 

but looking at the form it has onClick="return check_values();"

this is a javascript event, so you need to make sure the form is not being submitted using AJAX

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.