KillerWolf Posted November 8, 2008 Share Posted November 8, 2008 Ok two things i need help with first one is if someone can make sure that this should work alright, no real big bugs in it. And 2. I not sure how i should go about validating the email address, i want it to look to see if their is a @ and . in the feild. Thank you for any help. <p class="headermain"></p> </p> <!--header text --> <?php //address the mail is to be sent to $mailTo="test@test.test, $req_email"; //mails to the user $mailFrom="test@test.test"; //mailing info $msgBody="The following was submitted on ".$sentdate."\n Name:\t".$name." Email:\t".$_POST['email']." Query:\n".$_POST['comments']; $xHeaders = "From: $mailFrom\nX-Mailer: PHP/" . phpversion(); //error msgs $req_name="Name"; $req_email="Email address"; $req_comments="missing comments"; //message that is displayed on the screen when mail is sent. $success_message="<b>Your message has been sent. Thank you for input.</b>"; $comments="Query from ".$_POST['comments']; if ($_POST['submit']) { $sentdate=Date("l F jS, Y"); //Check if there is a response from the required fields. if(!$_POST['name']&&$req_name){ $missing[]=$req_name; $nosuccess[0]=' class="nosuccess"'; } if(!$_POST['email']&&$req_email){ $missing[]="Email address"; $nosuccess[1]=' class="nosuccess"'; } if(!$_POST['comments']&&$req_comments){ $missing[]="Comments"; $nosuccess[2]=' class="nosuccess"'; } if(count($missing)>0){ $s=""; if(count($missing)>1){ $s="s"; } print "<div class=\"errormsg\">You missed out the following required field$s:<br><ul>\n"; for ($i=0; $i<count($missing); $i++){ print "<li>$missing[$i]</li>"; } print"</ul></div>"; // exit; } //endifcountmissing else{ if(mail($mailTo, $comments, stripslashes($comments), $xHeaders)){ // confirmation print "<p>$success_message</p>" ; print "<h1>Message successfully sent</h1>"; } else{print"<p>Sorry, could not send mail, please try later.</p>"; } } } else{ } ?> <form action="<?php $_SERVER['PHP_SELF']?>" method="post"> <h3>Contact Us</h1> <fieldset> <p class="headermain"<?php print $nosuccess[0];?>> <b>Name:</b> <input type="text" name="name" value="<?php if (!empty($_POST['name'])) Echo $_POST['name'];?>" size="20" maxlength="40" /></p> <p class="headermain" <?php print $nosuccess[1];?>> <b>Email:</b><input type="text" name="email" value="<?php if (!empty($_POST['email'])) Echo $_POST['email'];?>"size="20" maxlength="40" /></p> <p class="headermain"<?php print $nosuccess[2];?>> <b>Comments:</b> <textarea name="comments" rows="5" cols="50"><?php if (!empty($_POST['comments'])) Echo $_POST['comments'];?><?php echo stripslashes($_POST['details']) ;?></textarea></p> <div><input type="submit" name="submit" value="submit" /> </div> </feildset> </td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/ Share on other sites More sharing options...
Jeremysr Posted November 8, 2008 Share Posted November 8, 2008 1. I can't read the code because it's all over the place... please indent properly. 2. Use regex to validate e-mail addresses, here is a function that will return 1 if it's valid or 0 if it isn't: function is_email_valid($email) { return preg_match('/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $email); } This regex is from the homepage of http://regular-expressions.info . Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685149 Share on other sites More sharing options...
KillerWolf Posted November 8, 2008 Author Share Posted November 8, 2008 cant seem to find how to edit my post. Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685154 Share on other sites More sharing options...
xcoderx Posted November 8, 2008 Share Posted November 8, 2008 u could do better with little piece of coding here is what u can do if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) { echo "Use a valid email address\n"; $error = "Email not sent\n"; echo $error; die ("Try again "); } Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685160 Share on other sites More sharing options...
KillerWolf Posted November 8, 2008 Author Share Posted November 8, 2008 oh thats tight, so just put that in were i have the existing email check? Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685161 Share on other sites More sharing options...
xcoderx Posted November 8, 2008 Share Posted November 8, 2008 yes exactly figure it out where u must add the code and u are done and nomore invalid email addresses Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685162 Share on other sites More sharing options...
KillerWolf Posted November 8, 2008 Author Share Posted November 8, 2008 thanks, ill figure out how to implement that now. but everything else looks alright? Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685163 Share on other sites More sharing options...
xcoderx Posted November 8, 2008 Share Posted November 8, 2008 indent ur codings properly first coz its very messy to even go through Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685165 Share on other sites More sharing options...
KillerWolf Posted November 8, 2008 Author Share Posted November 8, 2008 tryihng to figure out how to edit the code i posted Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685166 Share on other sites More sharing options...
KillerWolf Posted November 8, 2008 Author Share Posted November 8, 2008 this is the best i can make it, it looks weird cause of this data box. <p class="headermain"></p> </p> <!--header text --> <?php //address the mail is to be sent to $mailTo="test@test.test, $req_email"; //mails to the user $mailFrom="test@test.test"; //mailing info $msgBody="The following was submitted on ".$sentdate."\n Name:\t".$name." Email:\t".$_POST['email']." Query:\n".$_POST['comments']; $xHeaders = "From: $mailFrom\nX-Mailer: PHP/" . phpversion(); //error msgs $req_name="Name"; $req_email="Email address"; $req_comments="missing comments"; //message that is displayed on the screen when mail is sent. $success_message="<b>Your message has been sent. Thank you for input.</b>"; $comments="Query from ".$_POST['comments']; if ($_POST['submit']) { $sentdate=Date("l F jS, Y"); //Check if there is a response from the required fields. if(!$_POST['name']&&$req_name) { $missing[]=$req_name; $nosuccess[0]=' class="nosuccess"'; } if(!$_POST['email']&&$req_email) { $missing[]="Email address"; $nosuccess[1]=' class="nosuccess"'; } if(!$_POST['comments']&&$req_comments) { $missing[]="Comments"; $nosuccess[2]=' class="nosuccess"'; } if(count($missing)>0) { $s=""; if(count($missing)>1) { $s="s"; } print "<div class=\"errormsg\">You missed out the following required field$s:<br><ul>\n"; for ($i=0; $i<count($missing); $i++) { print "<li>$missing[$i]</li>"; } print"</ul></div>"; // exit; } //endifcountmissing else { if(mail($mailTo, $comments, stripslashes($comments), $xHeaders)){ // confirmation print "<p>$success_message</p>" ; print "<h1>Message successfully sent</h1>"; } else { print"<p>Sorry, could not send mail, please try later.</p>"; } } } else { } ?> <form action="<?php $_SERVER['PHP_SELF']?>" method="post"> <h3>Contact Us</h3> <fieldset> <p class="headermain"<?php print $nosuccess[0];?>> <b>Name:</b> <input type="text" name="name" value="<?php if (!empty($_POST['name'])) Echo $_POST['name'];?>" size="20" maxlength="40" /></p> <p class="headermain" <?php print $nosuccess[1];?>> <b>Email:</b><input type="text" name="email" value="<?php if (!empty($_POST['email'])) Echo $_POST['email'];?>"size="20" maxlength="40" /></p> <p class="headermain"<?php print $nosuccess[2];?>> <b>Comments:</b> <textarea name="comments" rows="5" cols="50"><?php if (!empty($_POST['comments'])) Echo $_POST['comments'];?><?php echo stripslashes($_POST['details']) ;?></textarea></p> <div> <input type="submit" name="submit" value="submit" /> </div> </feildset> Quote Link to comment https://forums.phpfreaks.com/topic/131881-please-help-me-with-my-contact-forum/#findComment-685180 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.