Articles

Why is my contact form not working properly?

August 17, 2010 at 15:56:09
Specs: Windows XP

Hi,

firstly I apologise if this is posted in the wrong topic or anything.

I have been developing a website now for around 3 weeks and have just started integrating PHP scripting into it to deal with various forms I am going to be providing on the site for registration/contacting me etc. I have already written the code for the contact form, which the html for looks like this:

<h3>Contact us</h3>

If you wish to speak to us about anything at all about our services or products, please do not hesitate to contact us! Simply fill in your details below with a description of your enquiry and we will endeavour to contact you within 24 hours.</p>
<form id="contactform" method="post" action="sendmail" onclick="contactformprocess.php">
Your full name:<input type="text" name="name" style="color:#000" size="20" maxlength="40" /><br />
<br />
Your email address:<input type="text" name="email" style="color:#000" size="20" maxlength="40" /><br />
<br />
Your message:<br />
<textarea name="message" rows="5" cols="40" ></textarea><br />
<input type="submit" value="Submit" name="submit" /><input type="reset" value="Clear" />
</form>

The php file which it relates to is as follows:

<?php
$to = 'myemailaddress';
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$subject = 'Message from: $name';
$message = $_REQUEST['message'] ;
$from = $_REQUEST['email'] ;
$additional_headers = 'noreply@mydomainname.co.uk';
$body = 'From: $name \n\n Email: $email \n\n Message: $message';
$sent = mail($to, $subject, $body, $headers, $from) ;
if($sent)
{echo "Thank you for your comments, please click the home button to return to our homepage";}
else
{echo "There has been a problem sending your mail, please go back using your browsers back button and try again";}

?>

The HTML looks fine on the page and I don't have problems with the design side of things, I have seperate CSS files to control the look and style of the page etc. My problem is, when I click the "submit" button, it just returns the php file above in text format in my browser window?! Wierd....

I know this might be an easy error to make but I have only just learned how to code HTML and CSS but have never done any PHP scripting at all... complete n00b!!

Help please!!!!! :)


See More: Why is my contact form not working properly?

Report •


#1
August 19, 2010 at 20:18:19

your form tag syntax is wrong.

Use this,

<form id="contactform" method="post" action="contactformprocess.php">


Report •
Related Solutions


Ask Question