Jump to content

please help me with my contact forum.


KillerWolf

Recommended Posts

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>

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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>	

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.