Jump to content

how can I create a form email?


Dark Knight
 Share

Recommended Posts

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

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.

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

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.

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

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.

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

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

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

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

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

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.

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

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

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>

Hi guys,did anyone spot the error here in why the email check is not working??Thanks
Link to comment
Share on other sites

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

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

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.

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...