| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Nov 2003 Location: Florida
Posts: 2,026
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Need some help with a contect form Hey everyone. I am working on a site and I need to get a contact form working. It sounds dumb but I have it on the page, but what do I need to do to get it to work. Its done in dreamweaver ????: NamePros.com http://www.namepros.com/programming/275012-need-some-help-with-contect-form.html </style> <form name="form1" method="post" action=""> <table width="450" border="0"> <tr> <td width="73">Name</td> <td width="367"><label> <input name="name" type="text" id="name"> </label></td> </tr> <tr> <td>Email</td> <td><label> <input name="email" type="text" id="email"> </label></td> </tr> <tr> <td>Comment</td> <td><label> <textarea name="comment" id="comment"></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input name="Submit" type="submit" class="button" value="Send"> <input name="Submit2" type="reset" class="button" value="Clear"> </label></td> </tr> </table> </form> |
| |
| | THREAD STARTER #5 (permalink) |
| Senior Member Join Date: Nov 2003 Location: Florida
Posts: 2,026
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I have PHP on my server. I found a script I can use and it will send mail... but no subject or message. And it sends from my server and not a email I specify. Maybe there is something missing <html> <head><title>PHP Mail Sender</title></head> <body> <?php /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */ $name = $HTTTP_POST_VARS ['name']; $email = $HTTP_POST_VARS['email']; $comment = $HTTP_POST_VARS['comment']; /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */ if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) { echo "<h4>Invalid email address</h4>"; echo "<a href='javascript:history.back(1);'>Back</a>"; } elseif ($subject == "") { ????: NamePros.com http://www.namepros.com/showthread.php?t=275012 echo "<h4>No subject</h4>"; echo "<a href='javascript:history.back(1);'>Back</a>"; } /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */ elseif (mail($email,$subject,$message)) { echo "<h4>Thank you for sending email</h4>"; } else { echo "<h4>Can't send email to $email</h4>"; } ?> </body> </html> |
| |
| | #6 (permalink) |
| NamePros Regular Join Date: Feb 2006
Posts: 584
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | This setting in phpini needs to be changed - sendmail_from Changing it changes what address appears in the from address. You need to have a form in order to send mail. If you don't want to, edit : $name = $HTTTP_POST_VARS ['name']; $email = $HTTP_POST_VARS['email']; $comment = $HTTP_POST_VARS['comment']; to $subject = " - Subject - "; $email = " - To Email - "; $message = " - To Message - "; Edit the content inside. |
| |
| | THREAD STARTER #7 (permalink) |
| Senior Member Join Date: Nov 2003 Location: Florida
Posts: 2,026
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I think I have been working on this to much tonight . I need to give it a rest and try again tommorow. I just need this http://www.kitcar.ws/test.html (just a test) To function. Like I said I can get it to send, but with no message and with a server email. So if anyone can help it would be great |
| |
| | #8 (permalink) |
| NamePros Regular Join Date: Feb 2006
Posts: 584
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Sorry, missing out on the form posted. Heres a fix : Code: <form name="form1" method="post" action=""> <table width="450" border="0"> <tr> <td width="73">Name</td> <td width="367"><label> <input name="name" type="text" id="name"> </label></td> </tr> <tr> <td>Email</td> <td><label> <input name="email" type="text" id="email"> </label></td> </tr> <tr> <td>Subject</td> <td><label> <input name="subject" type="text" id="subject"> </label></td> </tr> <tr> <td>Message</td> <td><label> <textarea name="message" id="message"></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input name="Submit" type="submit" class="button" value="Send"> <input name="Submit2" type="reset" class="button" value="Clear"> </label></td> </tr> </table> </form> Code: /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$name = $HTTP_POST_VARS ['name'];
$email = $HTTP_POST_VARS['email'];
$message = $HTTP_POST_VARS['message'];
$subject = $HTTP_POST_VARS['subject'];
/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}
/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email,$subject,$message)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>
</body>
</html> |
| |
| | #10 (permalink) | ||||
| Domains my Dominion Join Date: Aug 2005 Location: Web 1.0
Posts: 9,552
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Also, if you are using third-party code make sure you understand the risk of E-mail injection: http://www.securephpwiki.com/index.php/Email_Injection
__________________ NameNewsletter.com - free lists of available domain names ZoneFiles.net (beta) - ccTLD and gTLD droplists | ||||
| |
| | THREAD STARTER #12 (permalink) |
| Senior Member Join Date: Nov 2003 Location: Florida
Posts: 2,026
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Thanks for everyones help. So does anyone have any idea of a simple script I can use. IM putting a site together as a favor to someone and dont really want to spend any money on it. This should have been simple and done by now..hhaha |
| |
| | #13 (permalink) |
| Senior Member Join Date: Dec 2006 Location: England
Posts: 1,568
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | This is my adapted version slipondajimmy, use it if you wish. PHP Code:
Last edited by Matthew.; 01-01-2007 at 07:31 AM.
|
| |
| | #15 (permalink) |
| Senior Member Join Date: Dec 2006 Location: England
Posts: 1,568
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I have only ever known that message to appear as sdsinc said when your exstension is .html or .htm Unless you have created a handler so php will parse in html files (not advised) your file extension must be .php |
| |
| | #16 (permalink) | ||||
| NamePros Regular Join Date: Feb 2006
Posts: 584
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
However, he asked for his contact form to be fixed with functionality. So I didn't make much changes to the script (how do i know what PHP version he has). Rename the file (the one Matthew provided) to *.php. | ||||
| |