Web Design and Development Forums

> Please Help With Simple Php Contact Form!

This is a discussion on "> Please Help With Simple Php Contact Form!" within the PHP Forum section. This forum, and the thread "> Please Help With Simple Php Contact Form! are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > PHP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 17th, 2008, 16:03   #1 (permalink)
New Member
 
Join Date: Apr 2008
Location: london
Age: 25
Posts: 4
Angry > Please Help With Simple Php Contact Form!

Hi All,

I'm sure you get this all a lot but I'm struggling to get a simple contact form to work. Here's the html side of things:

which can be found at: http://www.stleonardshouse.co.uk/contact.html

Code: Select all
<form action="sendmail.php" method="post" name="ContactForm" id="ContactForm">
<div class="col1">
<div class="row">
<input name="name" type="text" class="input" id="name" value="Name:" />
</div>
<div class="row">
<input name="email" type="text" class="input" id="email" value="Email:" />
</div>
</div>
<div class="col2">
<div class="row1">
<textarea name="message" cols="1" rows="1" id="message">Message:</textarea>
<br />
<div class="div">
<input type="submit" name="submit" value="Submit" class="submit-button" />
</div>
now I have tried a hundred different php scrips to get this SIMPLE form to work, with no luck. I need the users name, email and message to be sent to email of *REMOVED* with the subject of 'Enquiry from St Leonard's House Website. If they dont enter an email I want it to display error.html and if its successful I need it to display thanks.html or something along those lines. Thats it! I'm not really worried about too much validation or spam protection or anything too complex, I just need something simple.

I was wondering if my server had anything to do with it and found this page on my hosts tech support pages:

http://www.fasthosts.co.uk/knowledge-base/?article_id=70


I do not have much experience with PHP scripting and I know someone out there could clear up this confusion for me in minutes with a simple script that I can upload and get this thing working once and for all!

Many thanks in advance,
Daniel

Last edited by saltedm8; Apr 17th, 2008 at 18:44. Reason: added [code] tags + email removed, you can add this yourself later
dbh21 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 17th, 2008, 18:41   #2 (permalink)
Lead Administrator
 
saltedm8's Avatar
 
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,061
Blog Entries: 1
Send a message via MSN to saltedm8
Re: > Please Help With Simple Php Contact Form!

please post the php script you are trying to use and we will see what is wrong

thank you
__________________
recipebite.co.uk - its a working progress...
saltedm8 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 17th, 2008, 23:24   #3 (permalink)
New Member
 
Join Date: Apr 2008
Location: london
Age: 25
Posts: 4
Re: > Please Help With Simple Php Contact Form!

<?php

ini_set("sendmail_from", "enquiries@stleonardshouse.co.uk");

mail("enquiries@stleonardshouse.co.uk", "Enquiry From St Leonard's House Website",

$_POST['message'], "From"$_POST['email'], "Name"$_POST['name'], "-f"$_POST['enquiries@stleonardshouse.co.uk'] );

header( "Location:http://www.stleonardshouse.co.uk/thanks.html" );

?>

Ive used this code in sendmail.php and it still doesnt work. The hosting company states:

'In order for the script to work, you need to specify, via a fifth -f parameter, the domain from which the mail is being sent. The PHP component uses SMTP, and all Fasthosts' SMTP servers have filters which ensure that the data returned by either the first or fifth mail parameter relates to one of your domains hosted by Fasthosts. The final part of the script thanks the visitor for the message. This is done by sending an HTTP header back to the visitor's browser telling it to load a file called thankyou.html from your domain. The header function allows you to send any HTTP header back to the browser.

I'm not sure what is wrong here... please help!
Thanks
dbh21 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 18th, 2008, 09:11   #4 (permalink)
New Member
 
Join Date: Jan 2008
Location: London, UK
Posts: 4
Send a message via ICQ to ooyes Send a message via Skype™ to ooyes
Re: > Please Help With Simple Php Contact Form!

The first thing we need to do is to write the feedback form itself. Put the following code in the <body> section of an HTML file named, say, feedback.html.

HTML: Select all
<form method="post" action="sendmail.php">
  Email: <input name="email" type="text" /><br />
  Message:<br />
  <textarea name="message" rows="15" cols="40">
  </textarea><br />
  <input type="submit" />
</form>
Basically the form asks the visitor for his email address (the field named "email" found in input name="email" above) and message (the field named "message" found in textarea name="message"), and presents him with a button which he can click to submit the contents of the form. When the form is submitted, it is "posted" (see the "method" attribute of the <form> tag) to a script named "sendmail.php" (also specified in the <form> tag).
The Feedback Form PHP Script

Now all that remains is to code "sendmail.php". This is made extremely easy by the facilities available in PHP. Type the following code into a file named "sendmail.php". Do not put anything else into that file, ie, don't put in any other HTML tags or headers, etc.
PHP: Select all

<?php
  $email 
$_REQUEST['email'] ;
  
$message $_REQUEST['message'] ;

  
mail"yourname@example.com""Feedback Form Results",
    
$message"From: $email" );
  
header"Location: http://www.example.com/thankyou.html" );
?>
When the form is submitted to sendmail.php, the contents of the "email" field in the form is put into a PHP variable called $_REQUEST['email']. Likewise the contents of the "message" field is put into the variable $_REQUEST['message'].


If you had named the fields in your form "emailofsender" and "contentsofmessage", then the information submitted in those fields would have been available to your script in the variables $_REQUEST['emailofsender'] and $_REQUEST['contentsofmessage'] respectively. I think you get the idea.


The first thing we do in our PHP script is to make the information that is submitted easily accessible to the rest of the program.
Firstly, we made a copy of the contents of $_REQUEST['email'] in a variable we call $email. This was done in the line
$email = $_REQUEST['email'] ;
Note that we don't really have to call this new variable $email - we could have called it $thingamajig if we wished, but it makes sense to name a variable with some meaningful name.





Likewise, in the next line, we made a copy (assigned) of $_REQUEST['message'] in a variable $message.
$message = $_REQUEST['message'] ;
Again, we could have named the new variable anything we wanted - but it's easier for us to understand the program if the variable name reflects what it does.


The real workhorse of this script is in the line beginning with "mail".
PHP: Select all

mail"yourname@example.com""Feedback Form Results",
  
$message"From: $email" ); 
mail is a special function in PHP that sends mail. The first parameter to mail is supposed to contain the email address you want the form contents to be sent to, such as your own email address. The second parameter is the "Subject" of the email message. The last two parameters are the content of the message and the headers you want sent, respectively. We want a "From" header so that we know who is sending the email to us and can reply to him/her if we need to.


Notice that, like many other programming languages, strings (sequences of characters) are enclosed in double quotes, such as "Feedback Form Results".


Variables like $message can be used as-is. Note also that you can also interpolate (introduce) the contents of the variable $email into a string, like "From: $email", so that if your $email string contained an address like "william@shakespeare.com", the final string that is passed to the mail function will be "From: william@shakespeare.com".


You can also use single quotes (such as those in 'Hi there') to quote strings, but when you do so, the variables included are not expanded. This is useful if, for some reason, you really want to pass the string 'From: $email' to mail without PHP translating that to "From: william@shakespeare.com".





You can't interpolate variables like $_REQUEST['email'] and $_REQUEST['message'] in the same way, which is why we assigned their contents to $email and $message. The latter are also easier to read anyway.


Finally, it is appropriate to thank the visitor for his message. This is done with the line


PHP: Select all

   header"Location: http://www.example.com/thankyou.html" ); 

</div> This line causes PHP to send an HTTP header back to the visitor's browser telling it to load the URL "http://www.example.com/thankyou.html". The "header" function allows us to send any HTTP header to the browser.


You will of course have to create such a file called "thankyou.html" with some sort of message to thank your visitor for his efforts, otherwise your visitor will be greeted with an unfriendly "404/File Not Found" error after he sends his message. You should also replace the URLs and email addresses with the correct ones if you want to use that script on your site.


By the way, the script has to be enclosed within the "<?php" and "?>" tags because the PHP processor treats all input as HTML code unless otherwise specified. On most systems, you can simply use "<?" and "?>" as the opening and closing tags to get the script to work, however if you want to be sure that your script will work on all systems, you should use the full "<?php" form for the opening tag.


Easy wasn't it? In just a few lines, you've written your first PHP script. And it's not some trivial and useless script - it is actually a working, usable program!
ooyes is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 18th, 2008, 15:37   #5 (permalink)
New Member
 
Join Date: Apr 2008
Location: london
Age: 25
Posts: 4
Re: > Please Help With Simple Php Contact Form!

The hosting company states:

'In order for the script to work, you need to specify, via a fifth -f parameter, the [COLOR=#3366CC ! important][COLOR=#3366CC ! important]domain[/color][/color] from which the mail is being sent. The PHP component uses SMTP, and all Fasthosts' [COLOR=#3366CC ! important][COLOR=#3366CC ! important]SMTP [COLOR=#3366CC ! important]servers[/color][/color][/color] have filters which ensure that the data returned by either the first or fifth mail parameter relates to one of [COLOR=#3366CC ! important][COLOR=#3366CC ! important]your [COLOR=#3366CC ! important]domains[/color][/color][/color] hosted by Fasthosts.

How do I do this?
dbh21 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 18th, 2008, 17:25   #6 (permalink)
 
Join Date: Jun 2007
Location: uk
Posts: 459
Re: > Please Help With Simple Php Contact Form!

You could try substituting this line

PHP: Select all

 ini_set("sendmail_from""enquiries@stleonardshouse.co.uk"); 

With this

PHP: Select all

ini_set("SMTP""yourSMTPserver.com"); 

dab42pat is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 19th, 2008, 08:38   #7 (permalink)
Junior Member
 
Join Date: Jul 2007
Location: Arkansas, USA
Age: 21
Posts: 44
Blog Entries: 1
Send a message via AIM to nashultz07 Send a message via MSN to nashultz07
Re: > Please Help With Simple Php Contact Form!

Quote:
Originally Posted by dbh21 View Post
The hosting company states:

'In order for the script to work, you need to specify, via a fifth -f parameter, the [COLOR=#3366CC ! important][COLOR=#3366CC ! important]domain[/color][/color] from which the mail is being sent. The PHP component uses SMTP, and all Fasthosts' [COLOR=#3366CC ! important][COLOR=#3366CC ! important]SMTP [COLOR=#3366CC ! important]servers[/color][/color][/color] have filters which ensure that the data returned by either the first or fifth mail parameter relates to one of [COLOR=#3366CC ! important][COLOR=#3366CC ! important]your [COLOR=#3366CC ! important]domains[/color][/color][/color] hosted by Fasthosts.

How do I do this?
From what I get that the company is saying is that in order for the script to work on their hosting sites you will need to specify one of their email addresses.

That page pretty much tells you how to set it up for their hosting requirements.

If you are needing me to explain, just let me know.

Hope this helps,
Nathon Shultz
__________________
nashultz07 CSS Trickery: CSS Tips and Tricks
nashultz07 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 18:16   #8 (permalink)
New Member
 
Join Date: Apr 2008
Location: london
Age: 25
Posts: 4
Re: > Please Help With Simple Php Contact Form!

yes, please explain - i dont know much about php scripting. thanks
dbh21 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP contact form redirect to same form Posie PHP Forum 14 Jan 29th, 2008 20:28
Contact Us Form - Help Please tygwyn JavaScript Forum 4 Sep 10th, 2007 10:36
php contact form geyids PHP Forum 5 Jun 14th, 2007 16:59
Contact us form help! NurseJenny PHP Forum 10 Jun 23rd, 2006 13:27
Need Quote Form and Contact Form Av8er Flash & Multimedia Forum 5 Oct 30th, 2003 17:14



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 10:59.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59