Kitty Posted December 27, 2006 Share Posted December 27, 2006 I have this email form, but everytime I try to send an email, it says[i] Please, go back and fill in a message![/i] even if I enter my message. Also, if I don't enter an email it sets it to anonymous, but I want it to be required and check if the email is valid. Here's the code:[code]<?php//Change these variables to your needs$yourmail = "mail@mail.com";if(isset($_POST['mail'])) { //Do this IF post is TRUE echo("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>"); if ($message!="") { //Do this IF message is TRUE if ($name!="") { //Do this IF name is TRUE if ($subject!="") { //Do this IF subject is TRUE if ($email!="") { } else { $email="Anonymous"; }//IF there is no email set by sender, SET it to Anonymous $message=htmlspecialchars($message); //htmlspecialchars makes sure " will show as " , instead of \" $name=htmlspecialchars($name); //Lets convert our name to htmlspecialchars as well $subject=htmlspecialchars($subject); $ip=GetHostByName($REMOTE_ADDR); $emailmessage= "Mail generated by: PHP Mail Script\nScript coded by: Arjan Peters\n---------------------------------------------------------\nName: $name\nE-Mail: $email\nIP: $ip\n---------------------------------------------------------\n$message"; //This is the layout for the e-mail message, \n indicates a New Line mail($yourmail, $subject, $emailmessage); //Send the mail PHP Function > mail(yourmail, subject, message) echo("<font size=\"2\" face=\"Verdana\">Thanks, $name. Your email has been sent.</font></td></tr></table>"); } else { //Do this IF subject is FALSE echo("<font size=\"2\" face=\"Verdana\">Please, go <a href=\"javascript:history.back();\">back</a> and fill in a subject!</font></td></tr></table>"); } } else { //Do this IF name is FALSE echo("<font size=\"2\" face=\"Verdana\">Please, go <a href=\"javascript:history.back();\">back</a> and fill in your name!</font></td></tr></table>"); } } else { //Do this IF message is FALSE echo("<font size=\"2\" face=\"Verdana\">Please, go <a href=\"javascript:history.back();\">back</a> and fill in a message!</font></td></tr></table>"); }} else { //Do this IF post is FALSE ?><table border="0" cellpadding="0" cellspacing="0"> <form method="post"> <tr> <td> <font size="2" face="Verdana"><b>Name<font color="#FF0000">*</font>:</b></font> </td> <td> <input type="text" name="name" value="" size="25" maxlength="40"> </td> </tr> <tr> <td> <font size="2" face="Verdana"><b>E-Mail:</b></font> </td> <td> <input type="text" name="email" value="" size="25" maxlength="50"> </td> </tr> <tr> <td> <font size="2" face="Verdana"><b>Subject:</b></font> </td> <td> <select name="subject"> <option value="QuestionComment">Question/Comment</option> <option value="Affiliation">Affiliation</option> <option value="LinkExchange">Link Exchange</option> <option value="GraphicRequest">Graphic Request</option> <option value="Bug">Bug Report</option> </select> </td> </tr> <tr> <td colspan="2"> <font size="2" face="Verdana"><b>Message<font color="#FF0000">*</font>:</b></font> </td> </tr> <tr> <td colspan="2"> <textarea rows="5" cols="35" name="message" maxlength="300"></textarea> </td> </tr> <tr> <td colspan="2"> <input type="reset" value="Reset"> <input type="submit" name="mail" value="Send"> </td> </tr> <tr> <td colspan="2" align="center"> <font size="2" face="Verdana"><font color="#FF0000">*</font> Required </font> </td> </tr></table><?php}?>[/code]Please, help! Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 27, 2006 Share Posted December 27, 2006 Change your variable calls to:$_POST['message']$_POST['name']$_POST['subject']$_POST['email']and see if that works Quote Link to comment Share on other sites More sharing options...
Kitty Posted December 27, 2006 Author Share Posted December 27, 2006 These ones?[code=php:0]if(isset($_POST['mail'])) { //Do this IF post is TRUE echo("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>"); if ($message!="") { //Do this IF message is TRUE if ($name!="") { //Do this IF name is TRUE if ($subject!="") { //Do this IF subject is TRUE if ($email!="") { } else { $email="Anonymous"; }//IF there is no email set by sender, SET it to Anonymous[/code]Sorry, I'm not good at php! Quote Link to comment Share on other sites More sharing options...
alpine Posted December 27, 2006 Share Posted December 27, 2006 modify all occurances of this kind:[color=blue] if ($message!="")[/color]to: [color=blue]if ($_POST['message']!="")[/color]This is because if register_globals is set to Off at your host (as they should be), variables won't be detected unless you declare them first.In this case you need to tell your script to look for $_POST['fieldname'] from your form.So in order to use them, $var = $_POST['var']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.