code to make sure email is real in php form

Status
Not open for further replies.

icomedsupply

New Member
Messages
7
Reaction score
0
Points
0
hey I've been searching on google and I can't seem to find the code that you put in a phpform that makes the form check if the email is real/require that certain parts of the form be filled out other wise it won't submit.

here is the code:
Code:
<?php
if (isset($_REQUEST['submit'])) {

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$faddress = $_POST['faddress'];
$laddress = $_POST['laddress'];
$state = $_POST['state'];
$country = $_POST['country'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$best_time = $_POST['best_time'];
$preferred = $_POST['preferred'];
$comments = $_POST['comments'];

            echo <<<thanks
<font face="Arial" size="3">
Thank you for your comments! <br><br>

We will get back to you as soon as possible
<br><br>
</font>
thanks;

	  $datetime = date("YmdHis");
		$mess = "<table border='0' width='500' bgcolor='#C0C0C0' cellspacing='1'>
    <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>First Name</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $fname . "</font></td>
    </tr>
    <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Last Name</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $lname  . "</font></td>
    </tr>
    <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Address</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $faddress . "</font></td>
    </tr>
    <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Address2</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $laddress . "</font></td>
    </tr>
    <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>State</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $state . "</font></td>
    </tr>
    <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Country</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $country . "</font></td>
    </tr>
    <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>City</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $city . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Zip</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $zip . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Phone</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $phone . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Fax</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $fax . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Mobile</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $mobile . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Email</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $email . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Best Time</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $best_time . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Preferred</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $preferred . "</font></td>
    </tr>
   <tr>
      <td bgcolor='#FFFFFF' align='center'><font face='Arial' size='2'><b>Comments</b></font></td>
      <td bgcolor='#FFFFFF'><font face='Arial' size='2'>" . $comments . "</font></td>
    </tr>
  </table>";
  
	   mail("EMAILADDRESS.GOES@HERE","Web Form Data",$mess,"From: $name<$email>\nReply-To: $email\nContent-Type: text/html; charset=ISO-8859-1\nX-Mailer: PHP/" . phpversion());
}
else{
echo "An unknown error occurred, please try again!";
}
?>
 

icomedsupply

New Member
Messages
7
Reaction score
0
Points
0
would it this be code?

Code:
function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

if (isset($_REQUEST['email']))
  {//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Invalid input";
    }

I inserted it into my php file, but it just gives me the error:
Parse error: syntax error, unexpected $end in /home/icocare/public_html/process.php on line 127

here is the code http://pastebin.com/m49ef4c1d

where exactly do I insert it?
 

Elesarr

New Member
Messages
193
Reaction score
3
Points
0
would it this be code?

Code:
function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

if (isset($_REQUEST['email']))
  {//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Invalid input";
    }
I inserted it into my php file, but it just gives me the error:
Parse error: syntax error, unexpected $end in /home/icocare/public_html/process.php on line 127

here is the code http://pastebin.com/m49ef4c1d

where exactly do I insert it?

the error you are receiving indicates you are missing a closing bracket } add a closing bracket at the end to the code you pasted and that error will vanish ;)

Edit:
I should say at least one closing bracket is missing. With the glance I gave your code adding one closing bracket should fix it.

so as not to confuse you here is where the brackets are not closed:

Code:
if (isset($_REQUEST['email']))
  [B]{[/B]//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Invalid input";
    }
[B][COLOR="Red"]}[/COLOR][/B]

add the red one and you will be good to go ;)
 
Last edited:
Status
Not open for further replies.
Top