Daytona10 Posted October 24, 2009 Share Posted October 24, 2009 Hi i am making a contact us form. My problem is the user fills it out presses submit, but then when I receive the email It does not show what I want it to show. It shows nothing. I want it to show the Name, Who its from, The date of birth fields, and the comment. This is the code I have. Also I can't find a code that the user has to fill in each field or it wont be submitted, if you have the chance can you include it? <body> <form id="form1" name="contactus" method="POST" action=""> <?php $Name = $_POST["Name"]; $Email = $_POST["Email"]; $Month = $_POST["Month"]; $Day = $_POST["Day"]; $YYYY = $_POST["YYYY"]; $Comment = $_POST["Comment"]; mail( "support@ludemanndistributors.net", "Feedback Form Results", $message, "From: $Email" ); ?> <table width="600" height="268" border="0"> <tr> <td width="152" height="49">Name*</td> <td width="287"><label> <input type="text" size="40" maxlength="40" name="Name"> <br /> </label></td> </tr> <tr> <td height="51">Email Address*</td> <td><label> <input type="text" size="40" maxlength="40" name="Email" /> </label></td> </tr> <tr> <td>Date of Birth*</td> <td><label> <select name="Month"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="Day"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="YYYY"> <option value="2012">2012</option> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> <option value="1940">1940</option> <option value="1939">1939</option> <option value="1938">1938</option> <option value="1937">1937</option> <option value="1936">1936</option> <option value="1935">1935</option> <option value="1934">1934</option> <option value="1933">1933</option> <option value="1932">1932</option> <option value="1931">1931</option> <option value="1930">1930</option> <option value="1929">1929</option> <option value="1928">1928</option> <option value="1927">1927</option> <option value="1926">1926</option> <option value="1925">1925</option> <option value="1924">1924</option> <option value="1923">1923</option> <option value="1922">1922</option> <option value="1921">1921</option> <option value="1920">1920</option> <option value="1919">1919</option> <option value="1918">1918</option> <option value="1917">1917</option> <option value="1916">1916</option> <option value="1915">1915</option> <option value="1914">1914</option> <option value="1913">1913</option> <option value="1912">1912</option> <option value="1911">1911</option> <option value="1910">1910</option> <option value="1909">1909</option> <option value="1908">1908</option> <option value="1907">1907</option> <option value="1906">1906</option> <option value="1905">1905</option> <option value="1904">1904</option> <option value="1903">1903</option> <option value="1902">1902</option> <option value="1901">1901</option> <option value="1900">1900</option> </select> </label></td> </tr> <tr> <td>Comments*</td> <td> <label> <textarea rows="5" cols="45" name="Comment" wrap="physical"></textarea><br /> </label></td> </tr> </table> <p> <label> <input type="submit" name="Submit" id="button" value="Submit" /> <input type="reset" name="Reset" id="button" value="Reset" /> </label> </p> <p> </p> <p>Everything with a "*" is required</p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/ Share on other sites More sharing options...
KevinM1 Posted October 24, 2009 Share Posted October 24, 2009 I don't think anyone is going to rewrite the whole thing for you and include form validation on a whim. You'll most likely need to work on it yourself (and we'll help you along the way with specific answers to specific problems), or you'll need to pay someone for that kind of work. That said, here's where you should look: $message is never set. I'm guessing that it's supposed to contain the values of the other variables, but you never actually do it. Thus, no message is in the e-mail. Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943625 Share on other sites More sharing options...
Daytona10 Posted October 24, 2009 Author Share Posted October 24, 2009 I dont mind if i dont get the validation ill get it sooner or later but for right now I just need that messege to show in the email. Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943630 Share on other sites More sharing options...
merylvingien Posted October 24, 2009 Share Posted October 24, 2009 Why have the years going back as far as 1900? I dont think there are many 109 year old internet users Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943632 Share on other sites More sharing options...
Daytona10 Posted October 24, 2009 Author Share Posted October 24, 2009 Why have the years going back as far as 1900? I dont think there are many 109 year old internet users You never know....maybe one will visit my site Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943634 Share on other sites More sharing options...
merylvingien Posted October 24, 2009 Share Posted October 24, 2009 Where is $message ? You havent defined what $message is supposed to be! Is it a combination of all the data that the user inputs, or is just the textarea or $Comment? Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943635 Share on other sites More sharing options...
Daytona10 Posted October 24, 2009 Author Share Posted October 24, 2009 Where is $message ? You havent defined what $message is supposed to be! Is it a combination of all the data that the user inputs, or is just the textarea or $Comment? How would you define the messege? Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943636 Share on other sites More sharing options...
Glen Posted October 24, 2009 Share Posted October 24, 2009 They are saying $message variable is empty I think you may have missed $message = $_POST['message']; Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943641 Share on other sites More sharing options...
Daytona10 Posted October 24, 2009 Author Share Posted October 24, 2009 Like this? <?php $Name = $_POST["Name"]; $Email = $_POST["Email"]; $Month = $_POST["Month"]; $Day = $_POST["Day"]; $YYYY = $_POST["YYYY"]; $Comment = $_POST["Comment"]; $message = $_POST['Name']; $message = $_POST['Email'] $message = $_POST['Month'] $message = $_POST['Day']; $message = $_POST['YYYY']; $message = $_POST['Name']; $message = $_POST['Comment']; mail( "support@ludemanndistributors.net", "Contact Us", $message, "From: $Email" ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943650 Share on other sites More sharing options...
mrMarcus Posted October 24, 2009 Share Posted October 24, 2009 a little space saver for ya: echo '<select name="YYYY">'; $start_year = 1900; $end_year = 2012; EDIT: had duplicate var names; for ($i=$start_year; $i<=$end_year; $i++) { echo '<option value="'.$i.'">'.$i.'</option>'; } echo '</select>'; replace your hard-coded year <select>...do the same for month and day (if you want of course); Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943651 Share on other sites More sharing options...
Glen Posted October 24, 2009 Share Posted October 24, 2009 <?php $Name = $_POST["Name"]; $Email = $_POST["Email"]; $Month = $_POST["Month"]; $Day = $_POST["Day"]; $YYYY = $_POST["YYYY"]; $Comment = $_POST["Comment"]; $message = "The name is:$Name <br> The Email adress is: $Email<br> THE D.O.B is:$Day/$Month/$YYYY <br> The Comment is $comment"; mail( "support@ludemanndistributors.net", "Feedback Form Results", $message, "From: $Email" ); ?> Try that. Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943661 Share on other sites More sharing options...
Daytona10 Posted October 25, 2009 Author Share Posted October 25, 2009 <?php $Name = $_POST["Name"]; $Email = $_POST["Email"]; $Month = $_POST["Month"]; $Day = $_POST["Day"]; $YYYY = $_POST["YYYY"]; $Comment = $_POST["Comment"]; $message = "The name is:$Name <br> The Email adress is: $Email<br> THE D.O.B is:$Day/$Month/$YYYY <br> The Comment is $comment"; mail( "support@ludemanndistributors.net", "Feedback Form Results", $message, "From: $Email" ); ?> Try that. Thank you it works VERY WELL and exactly what i wanted. Kudos to you. Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943770 Share on other sites More sharing options...
keldorn Posted October 25, 2009 Share Posted October 25, 2009 Thank you it works VERY WELL and exactly what i wanted. Kudos to you. That code might work, but there few things to consider since Nothing is validated. I can send, 0. Email message with unlimited message body,name,month,day,year,name character text. 1. Email messages with html in them 2. Post messages to your contact form with a bot and annoy you. 4. Send email with unvalidated email. Here is a function you will want to limit text with. Substr(); Prevent bots with a good free captcha. http://www.phpcaptcha.org/ Remove html from message with. strip_tags(); Email validation function. function valid_email($Email) { // This regex works pretty well. if(! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $Email)) { // Were here? Its bad. return false; } return true; } Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943775 Share on other sites More sharing options...
mikesta707 Posted October 25, 2009 Share Posted October 25, 2009 you dont really need to worry about html tags unless you are sending an HTML email. seem to be sending a plain text email, so any html will come up as plain text. However, besides that keldorn is correct, you should think about some validation Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943776 Share on other sites More sharing options...
Daytona10 Posted October 25, 2009 Author Share Posted October 25, 2009 well do you know any tutorials on validation or tips on it? Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943781 Share on other sites More sharing options...
mikesta707 Posted October 25, 2009 Share Posted October 25, 2009 well keldorn provided the standard email validation function. you can check the length of strings via the strlen(), and if the lengths are too long, then tell the user whatever is too long. for example if (strlen($comment) > 500){ echo "Comment too long!"; exit(); } that would limit the length of the comment to no more than 500 characters. you could do the same for the others. to protect against getting spammed, you could create a session for a user, and if they submitted the form, set the session to true, or something. then check the session before you send the email Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943782 Share on other sites More sharing options...
keldorn Posted October 25, 2009 Share Posted October 25, 2009 well do you know any tutorials on validation or tips on it? Here is a contact form I wrote awhile ago. Feel free to dissect it and learn from it structure. It uses smarty however, so dont pay much attention to the $smarty things, unless you want to use smarty. But smarty allows me to create user friendly error message, alot better then exit; or having to invent some error message functionality. include 'config.php'; include 'securimage.php'; // some stuff // If a post then it means there submitting the form if($_POST){ $error_msg = false; $contact_email = trim($_POST['EmailAddress']); //Allow max 35 characters in subject $contact_subject = substr(strip_tags($_POST['Subject']),0,35); // Allow max 25 characters $contact_name = substr($_POST['FullName'],0,25); // Strip html tags, and trim the content to max 600 characters $contact_message = substr(strip_tags($_POST['Message']),0,600); $contact_captcha = trim($_POST['cap_code']); //Validate Email if(!empty($contact_email)){ if(!valid_email($contact_email)){ $error_msg .= "<li>Please use a valid email.</li>"; $contact_email = false; } } else { //---Show this message if they left is blank $error_msg .= "<li>Your forgot to fill out your email.</li>"; } if(empty($contact_message)){ $error_msg .= "<li>You forget to fill out message!</li>"; } if(empty($contact_name)){ $error_msg .= "<li>You forget to fill out your name"; } if(empty($contact_subject)){ $error_msg .= "<li>You forgot to fill out your subject line</li>"; } if(!empty($contact_captcha)){ $img = new Securimage(); $valid = $img->check($contact_captcha); // Validate captcha if != true is bad if($valid != true) { // If capctha is wrong. $error_msg .= "<li>Sorry the captcha was wrong. Are you Human? </li>"; } } else { // They forget to fill out the captcha $error_msg .= "<li>You forgot to fill out the captcha</li>"; } //ERROR? Send error message and back any of the message they did fill out if($error_msg){ $smarty->assign('contact_email',$contact_email); $smarty->assign('contact_subject',$contact_subject); $smarty->assign('contact_name',$contact_name); $smarty->assign('contact_message',$contact_message); $smarty->assign('error_msg',$error_msg); $smarty->display('contact.tpl'); exit; } // No error? Continue... $mydate = date ( 'l, F d Y g:i A',time()+240 ); // e-mail subject $subject = "Message submitted using Contact Us form"; // e-mail message $message = "You have received a contact message:\r\n" ."----------------------------------------------------------------\r\n" ."Contact Name: $contact_name\r\n" ."Subject: $contact_subject\r\n" ."Submitted: $mydate\r\n" ."From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n" ."Message: $contact_message\r\n" ."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; $headers = "From: $contact_name <$contact_email>\n" ."Reply-To: $contact_email\n" ."X-Mailer: PHP/".phpversion(); mail("{$admin_email}","Website Contact Form:{$contact_subject}", $message, $headers); // Set Success message $smarty->assign('success_msg',"<strong>Thank you, your inquiry was sent to the administrator of Website!</strong>"); } // end of if($_POST) Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943784 Share on other sites More sharing options...
Daytona10 Posted October 25, 2009 Author Share Posted October 25, 2009 well do you know any tutorials on validation or tips on it? Here is a contact form I wrote awhile ago. Feel free to dissect it and learn from it structure. It uses smarty however, so dont pay much attention to the $smarty things, unless you want to use smarty. But smarty allows me to create user friendly error message, alot better then exit; or having to invent some error message functionality. include 'config.php'; include 'securimage.php'; // some stuff // If a post then it means there submitting the form if($_POST){ $error_msg = false; $contact_email = trim($_POST['EmailAddress']); //Allow max 35 characters in subject $contact_subject = substr(strip_tags($_POST['Subject']),0,35); // Allow max 25 characters $contact_name = substr($_POST['FullName'],0,25); // Strip html tags, and trim the content to max 600 characters $contact_message = substr(strip_tags($_POST['Message']),0,600); $contact_captcha = trim($_POST['cap_code']); //Validate Email if(!empty($contact_email)){ if(!valid_email($contact_email)){ $error_msg .= "<li>Please use a valid email.</li>"; $contact_email = false; } } else { //---Show this message if they left is blank $error_msg .= "<li>Your forgot to fill out your email.</li>"; } if(empty($contact_message)){ $error_msg .= "<li>You forget to fill out message!</li>"; } if(empty($contact_name)){ $error_msg .= "<li>You forget to fill out your name"; } if(empty($contact_subject)){ $error_msg .= "<li>You forgot to fill out your subject line</li>"; } if(!empty($contact_captcha)){ $img = new Securimage(); $valid = $img->check($contact_captcha); // Validate captcha if != true is bad if($valid != true) { // If capctha is wrong. $error_msg .= "<li>Sorry the captcha was wrong. Are you Human? </li>"; } } else { // They forget to fill out the captcha $error_msg .= "<li>You forgot to fill out the captcha</li>"; } //ERROR? Send error message and back any of the message they did fill out if($error_msg){ $smarty->assign('contact_email',$contact_email); $smarty->assign('contact_subject',$contact_subject); $smarty->assign('contact_name',$contact_name); $smarty->assign('contact_message',$contact_message); $smarty->assign('error_msg',$error_msg); $smarty->display('contact.tpl'); exit; } // No error? Continue... $mydate = date ( 'l, F d Y g:i A',time()+240 ); // e-mail subject $subject = "Message submitted using Contact Us form"; // e-mail message $message = "You have received a contact message:\r\n" ."----------------------------------------------------------------\r\n" ."Contact Name: $contact_name\r\n" ."Subject: $contact_subject\r\n" ."Submitted: $mydate\r\n" ."From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n" ."Message: $contact_message\r\n" ."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; $headers = "From: $contact_name <$contact_email>\n" ."Reply-To: $contact_email\n" ."X-Mailer: PHP/".phpversion(); mail("{$admin_email}","Website Contact Form:{$contact_subject}", $message, $headers); // Set Success message $smarty->assign('success_msg',"<strong>Thank you, your inquiry was sent to the administrator of Website!</strong>"); } // end of if($_POST) so how where would i insert the validation part? Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943790 Share on other sites More sharing options...
keldorn Posted October 25, 2009 Share Posted October 25, 2009 so how where would i insert the validation part? That code is not for c/p. It just an blueprint. But it already has validation. Thats what the functions are being used around the $_POST's and assigning them to a variable. and also the if(empty($var) checks are validation to check if its not empty. Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943794 Share on other sites More sharing options...
Daytona10 Posted October 25, 2009 Author Share Posted October 25, 2009 so how where would i insert the validation part? That code is not for c/p. It just an blueprint. But it already has validation. Thats what the functions are being used around the $_POST's and assigning them to a variable. and also the if(empty($var) checks are validation to check if its not empty. :'( Quote Link to comment https://forums.phpfreaks.com/topic/178864-whats-wrong-with-this/#findComment-943799 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.