This is a discussion on "Comment form" within the Web Page Design section. This forum, and the thread "Comment form are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
Comment form
|
||
| Notices |
![]() |
|
|
LinkBack (1) | Thread Tools |
#1
|
|||
|
|||
|
Comment form
Hi I have created a comments form in php, which is located at www.galaxywindows.co.uk/comments.php
However when i click submit the message isn't sent to my email, Does anyone know why this might be. Below is the code. Part 1 - Comments.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php if(isset($_GET['posted'])) { $to = 'jonbenitos@gmail.com'; //Email address to send it to $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $message = $_POST['message']; //This is the body of the email. You can modify it... $body = 'Name: ' . $fname . ' ' . $lname . ' Email: ' . $email . ' Message: ' . $message; //Send the message... if(mail($to, 'Site Message', $body)) { die('Success!'); } else { die('Failure!'); } } ?> <form method="Post" action="http://www.galaxywindows.co.uk/comments.php?posted=yes"> <table> <tr> <td><label for="fname">First Name:</label></td> <td><input type="text" name="fname" /></td> </tr> <tr> <td><label for="lname">Last Name:</label></td> <td><input type="text" name="lname" /></td> </tr> <tr> <td><label for="email">E-Mail:</label></td> <td><input type="text" name="email" /></td> </tr> <tr> <td><label for"message">Message:</label></td> <td><textarea name="message"></textarea></td> </td> <tr> <td><input type="submit" /></td> </tr> </table> </form> </body> </html> Part 2 - Code.php <?php if(isset($_GET['posted'])) { $to = 'jonbenitos@gmail.com'; $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $message = $_POST['message']; //This is the body of the email. You can modify it... $body = 'Name: ' . $fname . ' ' . $lname . ' Email: ' . $email . ' Message: ' . $message; //Send the message... if(mail($to, 'Site Message', $body)) { die('Success!'); } else { die('Failure!'); } } ?> |
|
#2
|
|||
|
|||
|
Re: Comment form
There are several problems with your code. The form method is defined as 'POST' but you have started your php checking with issset($_GET['posted']). Remove the ?posted=yes' from your action url and give your submit button a name and a value. Both of which can be 'posted' if you like. Your call to mail() does not include the forth variable. This can be a single thing or it can be a headers variable containing many elements that make up the header information. At the very least it should have a 'From: ...' otherwise you risk the email getting treated like 'spam' and being filtered out. |
|
#3
|
|||
|
|||
|
Re: Comment form
could you post me the corrected code, I would be very grateful because I'm not sure how to get it working.Thanks alot
Regards |
|
#4
|
|||
|
|||
|
Re: Comment form
Maybe you should try to fix the code yourself. I doubt anyone is going to do it for you. But they will be happy to help you if you get stuck. I may be wrong but I don't understand why you have die twice in your code with one echoing success? I could be wrong but I personally have never seen that in a mail script. As far as I know die kills the script.
|
|
#5
|
|||
|
|||
|
Re: Comment form
Last Blog Entry: Whats in a name? (Feb 20th, 2008)
|
![]() |
| Tags |
| comment, form |
| Thread Tools | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://webforumz.com/web-page-design/7625-comment-form.htm
|
||||
| Posted By | For | Type | Date | |
| Simple Contact Form « FocusedTutorials.com | This thread | Refback | Dec 26th, 2006 20:15 | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Comment Box In JavaScript? | kela | JavaScript Forum | 2 | Feb 14th, 2008 09:36 |
| how to create a comment page? | kool77 | Web Page Design | 5 | Jun 24th, 2007 09:26 |
| Comment the Logo | Superman | Graphics and 3D | 3 | Apr 6th, 2007 19:59 |
| Comment Box | Travis R | Web Page Design | 2 | Oct 11th, 2006 18:05 |
| comment | accessman | Databases | 3 | Sep 19th, 2005 11:36 |