Jump to content
xisto Community
Sign in to follow this  
Sten

Need Help With Form! help?

Recommended Posts

Well, for my site i need a contact form and a few other forms. ive written all the html.
I need the php for it though, im not great at php and some help would be nice! no tutorials or anything seem to work so im gathering im doing it wrong.

Whoever wants to help, if u would like to, could you also explain?

Here ist the form so u no wot to use:

<form action="contact_send.php" method="post"><table width="510" border="0"><tr><td width="50"><font size="2" face="verdana"><b>Habbo Name:</td><td><input size="25" name="Name"></td></tr><td><font size="2" face="verdana"><b>Email Address:</td><td><input size="25" name="Email"></td></tr><td><font size="2" face="verdana"><b>Reason:</td><td><select name="Reason"><option>Feedback</option><option>Complaint</option><option>Idea</option><option>Rare Value Suggestion</option><option>Help Me</option><option>Other</option></select></td></tr><tr><td><font size="2" face="verdana"><b>Your Message:</td><td><textarea name="Message" rows="6" cols="40"></textarea></td></tr><tr><td><input type="submit" name="Send" value="Send Message"></td></tr></table>

and i also just realised that i forgot to add the </form> to the end. lol. would that be y it isnt working? the cpanel isnt working at the moment to change it!

anyway, thanks in advance for any help!

i wonder if i shouldve put this in the programming section somewhere... lol
Edited by Sten (see edit history)

Share this post


Link to post
Share on other sites

These are the form names that you used: Name, Email, Message, Reason

Guessing that this is a registration code that you are working on, you make a new php file, and write the following.

Make sure you are connected to the database, and you have supplied the username, password, and the correct host information.

<?PHP//Fill this up. Make sure that the table has only 4 fields, which is the username, user email, message, and reason.$tablename = "";$user_name = $_GET[Name];$user_email = $_GET[Email];$user_message = $_GET[Message];$user_reason = $_GET[Reason];$QUERY = "INSERT INTO $tablename VALUES ($user_name, $user_email, $user_message, $user_reason)";$RESULT = mysql_query($QUERY);if ($RESULT){print "The information was added to the database";}else {print "There was an error. Maybe you weren't connected to the database?";}?>

If your table which the values will be inserted to has more fields, please tell me so I can edit this post or make a new post to help you out.

Good luck

Share this post


Link to post
Share on other sites

and i also just realised that i forgot to add the </form> to the end. lol. would that be y it isnt working?

No matter whether it works or not (and it might depending on the browser being used), it is always good practice to close each and every one of the tags. It is a W3C standard, after all.

 

What you should change, however, is the drop-down box code. Instead of

 

<select name="Reason"><option>Feedback</option><option>Complaint</option><option>Idea</option><option>Rare Value Suggestion</option><option>Help Me</option><option>Other</option></select>

 

use

 

<select name="Reason"><option value="Feedback">Feedback</option><option value="Complaint">Complaint</option><option value="Idea">Idea</option><option value="Rare Value Suggestion">Rare Value Suggestion</option><option value="Help Me">Help Me</option><option value="Other">Other</option></select>

 

This way you define values to be sent to the PHP file.

 

As for the PHP code, with slight alterations to the one Sten provided, it should mail you properly.

 

<?php$to = 'someone@example.com';$subject = 'Contact e-mail';$user_name = $_GET['Name'];$user_email = $_GET['Email'];$user_message = $_GET['Message'];$user_reason = $_GET['Reason'];$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";if !( mail( $to, $subject, $message ) ) {   echo 'Mail not sent!';}?>

The first two variable should be edited to contain you e-mail address and the message subject you want to use. The next four rows insert all the sent data into four variables, which are then joined to for the mail body. I hope that the only thing you might find confusing is "\n" - it defines a new line in the message body. With that in mind, you would receive an e-mail like this:

 

Name: John Smith

E-mail: johnsmith@gmail.com

 

John Smith's message.

 

Reason: Feedback


The last several lines send the e-mail, and failure to do so results in a "Mail not sent" message.

 

Be sure to inform me of any problems you encounter.

Share this post


Link to post
Share on other sites

Well... it sends to me. I had to change $_GET to $_REQUEST to get it to actually display the stuff in the email.but, no matter if it send or not, it still ses that the mail wasnt sent.wot do i change to the script to make it just go to a thankyou page once it sends?

Share this post


Link to post
Share on other sites

change this:

<?php$to = 'someone@example.com';$subject = 'Contact e-mail';$user_name = $_GET['Name'];$user_email = $_GET['Email'];$user_message = $_GET['Message'];$user_reason = $_GET['Reason'];$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";if !( mail( $to, $subject, $message ) ) {   echo 'Mail not sent!';}?>
to this:
<?php$to = 'someone@example.com';$subject = 'Contact e-mail';$user_name = $_GET['Name'];$user_email = $_GET['Email'];$user_message = $_GET['Message'];$user_reason = $_GET['Reason'];$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";if !( mail( $to, $subject, $message ) ) {   echo 'Mail not sent!';}else {echo '<script language="JavaScript" type="Text/JavaScript">document.location = 'thankyou.php';</script>';}?>
Replace thankyou.php with the filename of your thank you page

Share this post


Link to post
Share on other sites

ty jay!ill try it now, i hope it works!after about 3 emails jay (habble) got it working for me so yeah... dont bother with this topic anymore <_<

Edited by Sten (see edit history)

Share this post


Link to post
Share on other sites

Yeah, this definitely wouldn't work with $_GET, as the data is sent through POST. I overlooked this, my bad <_<

 

Also, instead of echoing a piece of JavaScript code for redirecting to the ThankYou page, you can also use the PHP header function.

 

if !( mail( $to, $subject, $message ) ) {   echo 'Mail not sent!';}else {   header('Location: http://http://ww38.yoursite.com/thankyou.php&%2339;&;;}

Bare in mind that this will not work if you have already printed out something on the page.

Share this post


Link to post
Share on other sites
<?php$to = 'someone@example.com';$subject = 'Contact e-mail';$user_name = $_GET['Name'];$user_email = $_GET['Email'];$user_message = $_GET['Message'];$user_reason = $_GET['Reason'];$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";$headers = 'From: webmaster@example.com' . "\r\n" .	'Reply-To: webmaster@example.com' . "\r\n";if !( mail( $to, $subject, $message,  $headers) ) {   echo 'Mail not sent!';}else {echo '<script language="JavaScript" type="Text/JavaScript">document.location = 'thankyou.php';</script>';}?>
Some Mail Servers require a From header in the mail() even though the php function lists it as an Optional part of the Function's parameters, so review the code above and notice that it uses the variable named $header to add the From and Reply-to headers for the mail script. I have seen mail fail because these headers are missing on the attempt to mail out stuff.

Also, this code does not show any error handling, so another problem might be that the client is leaving one of the required fields blank? Check the Mail function information at the php site: http://php.net/.
Edited by jlhaslip (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.