Dark Knight Posted June 24, 2006 Share Posted June 24, 2006 Hi, I saw your site and I like it very much. I bealive you know how to create a form for emails. Can you show me a code? I'd like the code to have this names: First Name = codeSecond Name = codeE-mail = codeComment = code (here I'd like to be a TEXTAREA)Submit = button codeReset = button code Thank you. Link to comment Share on other sites More sharing options...
SmokingMan Posted June 24, 2006 Share Posted June 24, 2006 Here's a good tutorial to get you started:W3C Schools Form Tutuorial Link to comment Share on other sites More sharing options...
scott100 Posted June 24, 2006 Share Posted June 24, 2006 I bealive you know how to create a form for emails. Can you show me a code?PHP is one language you could use to process the form by email: http://www.w3schools.com/php/php_mail.aspYour server must support php and the mail() function. Link to comment Share on other sites More sharing options...
lord_of_the_rings802 Posted June 25, 2006 Share Posted June 25, 2006 I am having the same issue. don't use 'mailto'. go to a php tutorial. Link to comment Share on other sites More sharing options...
monty 187 Posted June 29, 2006 Share Posted June 29, 2006 PHP is one language you could use to process the form by email: http://www.w3schools.com/php/php_mail.aspYour server must support php and the mail() function.<{POST_SNAPBACK}> Hi, i was wondering if you knew the best way to validate a form by mail set up with php. I have got the mail working but want to ensure all fields have been filled and that the email address is a valid one. Link to comment Share on other sites More sharing options...
scott100 Posted June 29, 2006 Share Posted June 29, 2006 Hi, i was wondering if you knew the best way to validate a form by mail set up with php. I have got the mail working but want to ensure all fields have been filled and that the email address is a valid one.<{POST_SNAPBACK}> Validate Emailto validate a field i use empty() functionif (empty($_POST["name"]){...}If you ask google you will find example on Form Validation Link to comment Share on other sites More sharing options...
aleksanteri Posted June 29, 2006 Share Posted June 29, 2006 Hi, i was wondering if you knew the best way to validate a form by mail set up with php. I have got the mail working but want to ensure all fields have been filled and that the email address is a valid one.<{POST_SNAPBACK}> PHP:$email = $_REQUEST["email"];$field1 = $_REQUEST["field1"];$field2 = $_REQUEST["field2"];$field3 = $_REQUEST["field3"];$field4 = $_REQUEST["field4"];if(!empty($field1) && !empty($field2) && !empty($field3) && !empty($field14) && str_match("@", $email) == "@" && str_match(".", $email))// form valid The email can be tricked however. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 29, 2006 Share Posted June 29, 2006 You can use a regular expression to check for any valid email address, and you can also do a domain lookup to make sure the domain actually exists if you want to go that far. Look at Scott's Google link, and follow the first result. There is a regular expression there, and also some functions for looking up the domain. You should read that page to understand how it works, but I'll paste it here: function checkEmail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(getmxrr($Domain, $MXHost)) { return TRUE; } else { if(fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; } }} Link to comment Share on other sites More sharing options...
monty 187 Posted June 30, 2006 Share Posted June 30, 2006 Thanks A million guys, i had rooted around and found the validation function, the problem is i am unsure where to call it from in the script! Is it when the submit button is pressed? if so could you explain how i go about this.<html><?phpif (isset($_REQUEST['email'])) { $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "mmontgomery@mmm.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; }else { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; }?></body></html> Link to comment Share on other sites More sharing options...
scott100 Posted June 30, 2006 Share Posted June 30, 2006 the problem is i am unsure where to call it from in the script! Is it when the submit button is pressed? if so could you explain how i go about this.i use thisif (isset($_POST['submit'])){//form has been submitted, validate it}else{form has not been submitted, display it}Again, Google is your friend Link to comment Share on other sites More sharing options...
monty 187 Posted June 30, 2006 Share Posted June 30, 2006 excellent. i have now inserted that and it appears to be processing the code but it is not picking up any Bad email addressesheres the code---><html><?php//has anything been submitted?if (isset($_REQUEST['email'])) { //if yes validate the mail address if(checkEmail($_REQUEST['email'])) { $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "mmontgomery@xxx.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else { echo "this is not a valid email!!"; } }else { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; }function checkEmail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(getmxrr($Domain, $MXHost)) { return TRUE; } else { if(fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; } }}?></body></html> Link to comment Share on other sites More sharing options...
holmedwa04 Posted June 30, 2006 Share Posted June 30, 2006 Hi, I saw your site and I like it very much. I bealive you know how to create a form for emails. Can you show me a code? I'd like the code to have this names: First Name = codeSecond Name = codeE-mail = codeComment = code (here I'd like to be a TEXTAREA)Submit = button codeReset = button code Thank you.<{POST_SNAPBACK}> Hi,I had the same problem, and these are some codes that I used to fix it:<FORM METHOD=POST ACTION="mailto:your email?subject=subject of email Post" ENCTYPE="text/plain"> This code will post all the data submitted by the viewer to your email, and if you set the subject, you can create a rule on your mail program, to make it go to a certain folder when recieved. It is avisable to note that this code will only work for viewers that have an email program, for it to send an email on their behalf, if not then I advise that you include this code aswell, it is just a simple mailto code with a subject and message in the body of the email, which the viewer can change to then send to you. <a href="mailto:your email?subject=subject&body=this can have upto 30 words">Click Here</a> This is also another bit of really nifty code that sends the user to a Thank-you page once they have submitted there post, but it must be noted the even if the post has not been submitted properly it will still send the user the Thank-you page. <INPUT TYPE="submit" VALUE="Submit Post"onclick="window.location='Link to your thank-you page';"> I hope this has helped you out, becuase it certainly help me! Link to comment Share on other sites More sharing options...
scott100 Posted June 30, 2006 Share Posted June 30, 2006 Hi,I had the same problem, and these are some codes that I used to fix it:<FORM METHOD=POST ACTION="mailto:your email?subject=subject of email Post" ENCTYPE="text/plain"> aaahhhhh never ever ever ever use mailto - it's cheap, nasty and unreliable. Stick with php, it'll see you good Link to comment Share on other sites More sharing options...
monty 187 Posted July 3, 2006 Share Posted July 3, 2006 excellent. i have now inserted that and it appears to be processing the code but it is not picking up any Bad email addressesheres the code---><html><?php//has anything been submitted?if (isset($_REQUEST['email'])) { //if yes validate the mail address if(checkEmail($_REQUEST['email'])) { $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "mmontgomery@xxx.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else { echo "this is not a valid email!!"; } }else { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; }function checkEmail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(getmxrr($Domain, $MXHost)) { return TRUE; } else { if(fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; } }}?></body></html><{POST_SNAPBACK}> Hi guys,did anyone spot the error here in why the email check is not working??Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted July 3, 2006 Share Posted July 3, 2006 What's the problem with it? Link to comment Share on other sites More sharing options...
reportingsjr Posted July 4, 2006 Share Posted July 4, 2006 I have one input for you guys, you are using the gloabal $_request, I wouldnt use that because it isnt really.. good? I would use $_post or $_get, depending on what you set it to. Thats just my opinion. But I seem to have forgotten why request isnt good.. oh well. I just know it isnt ill look it up if you want backup.. Link to comment Share on other sites More sharing options...
monty 187 Posted July 4, 2006 Share Posted July 4, 2006 What's the problem with it?<{POST_SNAPBACK}> The problem is that the code does not seem to be validating the email. It allows me to enter just a row of characters without an @. Im thinking it is a dodgy call to the validate function call but i cant see it!!ThanksGuys!! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 4, 2006 Share Posted July 4, 2006 Well it should definately catch the missing @. Try this and see what it does: if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) echo "The mail is valid";else echo "The mail is not valid"; Put your email variable in there. Link to comment Share on other sites More sharing options...
monty 187 Posted July 5, 2006 Share Posted July 5, 2006 Well it should definately catch the missing @. Try this and see what it does:if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) echo "The mail is valid";else echo "The mail is not valid"; Put your email variable in there. <{POST_SNAPBACK}> Ok i have set it up like this as a test,<html><body><?php $email="fulmont99@gmail.com"; if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { echo "The mail is valid"; } else { echo "The mail is not valid"; } echo " $email";?></body></html> and it is giving invalid?? plus even if i do a "sd;fjshdfklj" it still says invalid? its making my brain sore! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2006 Share Posted July 5, 2006 OK, this one works: $pattern = '/^[A-z0-9_\-\.]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{2,4}$/';if (preg_match($pattern, $email)){ echo "The mail is valid\n";}else{ echo "The mail is not valid\n";} Thanks to Zend. Link to comment Share on other sites More sharing options...
monty 187 Posted July 5, 2006 Share Posted July 5, 2006 OK, this one works:$pattern = '/^[A-z0-9_\-\.]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{2,4}$/';if (preg_match($pattern, $email)){ echo "The mail is valid\n";}else{ echo "The mail is not valid\n";} Thanks to Zend. <{POST_SNAPBACK}> oh man! that is excellent!!Thanks a mill!!!!!!!!!!!!!!!!!!!!!!!!!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now