Jump to content


Photo

contact us form


  • Please log in to reply
14 replies to this topic

#1 Ricklord

Ricklord
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 26 July 2006 - 04:36 PM

Hi peeps,

I don't usually ask questions in forums, but this one has been bugging me for the last few hours and ive read so many tutorials on how to do the contact us form but it just isnt working properly.

please view my html side at: http://www.creativec...contact_us.html

The script is available at: http://www.creativec...rm/contact.phps

I dont know why but this form just wont work it was working at the strt when i tested it but as i have put it into my actual site and added a few check boxes it doesnt work.

When the form is submitted it just goes to the error text i have put into the php script.

Im not a coder so please go easy on me. Ive tried to put different parts out of different scripts into one which is why it might not be working.

If anyone can help i would be most grateful

Cheers

Rick

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 04:41 PM

This is because you havn't given your submit button a name.
Change:
<input value="Submit Comments" type="submit">
to
<input value="Submit Comments" name="submit" type="submit">

Also I would recommend you to validate user input (your post variables). As your email script will be prone to spam! Malicous users will be able to send multiple emails in one go! Also you font validate for valid email addresses.

#3 Ricklord

Ricklord
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 26 July 2006 - 04:49 PM

sweet!!! thanks!!!

i did look at the but becuase it was going through to the contact.php page thought the submit button was working fine and assumed it was a problem with the php script.

added <<<<how do you mean vaildate the email address, is this a few lines of code i need to add?>>>>>>

But thanks, its working now.

How do i get the email address entered to come up as the sender in my inbox, it just says the email is from creativecogs.co.uk???

and finally how do i get it to go to a thankyou.html page after the script is executed instead of the echo command???

thanks again for spotting that submit error and so quickly.

Rick :):):):)

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 05:04 PM

You'll be best of searching for form validation tutorials. For your setup I would recommend you to do javascript form validation and possibaly PHP form validation too just incase the user has javascript turned off. SO fi you search for form validation tutorials with google you'll get a ton of results.

#5 Ricklord

Ricklord
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 26 July 2006 - 05:09 PM

Ok will do a search for the validator.

Any idea on how to forward onto a html page rather than the echo command i am using? I have searched for this but had no look, dont even know if im typing the right thing into google.

Also having the email address entered come through as the sender in my inbox?

Cheers

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 July 2006 - 05:20 PM

I would recommend always doing validation via PHP and don't depend on Javascript.  Spambots that will try to use your form for malicious activity will not use your form, but will send data directly to your processing script, thereby negating any Javascript validation being done on the client side.

Ken

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 05:25 PM

Use header:
header("Location: thanx.html");
Make sure there is no output before the use of this function.

To show who sent the email you'll want to send additional headers (4th parameter for mail function). A bit like this:
$header = "From: {$name}<{$email_field}>";

    mail($to, $subject, $body, $header);
This where your validation is most important! As your contact form is now prone to spam! Now you are using custom headers!

#8 jworisek

jworisek
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 26 July 2006 - 05:36 PM

slightly off topic, but are the exploits of mail scripts only possible if you place user input into the header?  Personally I don't put the users email address as From:.  I just put our website so that we know it was submitted from the web and then the users email is listed in the body.

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 05:40 PM

So you dont want to put the users name and email in the From bit? Just your website? If thats the case you can do this:
$header = "From: mysite.com<me@mysite.com>";


#10 Ricklord

Ricklord
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 26 July 2006 - 05:46 PM

Hi Again,

got the header in the right place and now forwarding on to a html page so thanks.

With the from field it is just coming up blank now any suggestions? or do i need to incorporate a validator before it will work?

this is my script now

<?php 
header("Location: http://www.creativecogs.co.uk/thankyou.html");

if(isset($_POST['submit'])) { 

$to = "rick@creativecogs.co.uk"; 
$subject = "Web Design Online enquiry"; 


$header = "From: {$name}<{$email_field}>";
$name_field = $_POST['name']; 
$email_field = $_POST['email'];
$telephone_field = $_POST['telephone']; 
$message = $_POST['message']; 

  
foreach($_POST['check'] as $value) { 
$check_msg .= "Checked: $value\n"; 
} 
  
$body = "From: $name_field\n E-Mail: $email_field\n Telephone: $telephone_field\n $check_msg Option: $option\n Message: $message"; 
  
echo "Data has been submitted to $to!"; 
mail($to, $subject, $body, $header); 
  
} else { 
echo "failed please try again"; 
} 
?>

Cheers

Rick

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 05:47 PM

You are still using the old header code:
$header = "From: {$name}<{$email_field}>";


#12 Ricklord

Ricklord
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 26 July 2006 - 05:50 PM

just read the other 2 posts about having the from field as the email address or setting it to show the web address.

Reason i want it to show me the email address is so i can have an autoresponder going from my webserver. dont know if this is possible with php but just thought if i can get the email address to show up then my auto responder on my web server can do this for me.

Rick

#13 Ricklord

Ricklord
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 26 July 2006 - 06:02 PM

ok sorry if im being 100% thick which i probably am but ive added the

$header = "From: {$name}<{$email_field}>";

it might be in the worng place though????

does it need to be above the $to and $subject or do i need to change these to

$header = "To: rick@creativecogs.co.uk>"
$header = "Subject: rick@creativecogs.co.uk>"

I don't understand php that well so thats probably wrong. could you let me know where im going wrong?

Rick

Thanks again

#14 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 06:15 PM

Your header var is in the wrong place, place it after the $message variable, like so:
$message = $_POST['message']; 
$header = "From: {$name}<{$email_field}>";


#15 Ricklord

Ricklord
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 26 July 2006 - 06:19 PM

WKD, thanks again :):):)

Now ill look at some tutorials for validation.

Thanks again

Rick




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users