Jump to content

Validation query


healy787

Recommended Posts

Hi guys. Im getting myself in a pickle. Here is what i have:

 

<?

 

  $name = $_REQUEST['name'] ;

  $surname = $_REQUEST['surname'] ;

  $email = $_REQUEST['email'] ;

  $message = $_REQUEST['message'] ;

  $subject1 = $_POST['subject1'] ;

  $mailing = $_POST['mailing'] ;

  $telephone = $_REQUEST['telephone'] ;

 

$to = "webmaster@letsgohost.co.uk";

$subject = "Message From Letsgohost Website";

$MsgHeader = "From: Lestgohost Website <support@letgohost.co.uk>\n";

$MsgHeader .= "Bcc: <webmaster@rydon-inn.co.uk> r\n";

$MsgHeader .= "MIME-Version: 1.0\n";

$MsgHeader .= "Content-type: text/html; charset=iso-8859-1\n";

$MsgBody = "

 

<html>

<head>

<title>Letsgohost</title>

</head>

<body>

 

<table style='padding-left:20px'>

<tr><td> </td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Name : $name</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Surname : $surname</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>&nbsp</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Email : $email</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>&nbsp</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Message subject : $subject1</font></font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>&nbsp</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Message : $message</font></font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>&nbsp</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Mailing : $mailing</font></font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>&nbsp</font></td></tr>

<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Telephone : $telephone</font></td></tr>

<tr><td> </td></tr>

</table>

 

</body>

</html>";

 

 

 

function checkEmail($email)

{

  // checks proper syntax

  if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email))

  {

    return false;

  }   

 

  // gets domain name

  list($username,$domain)=split('@',$email);

  // checks for if MX records in the DNS

  $mxhosts = array();

  if(!getmxrr($domain, $mxhosts))

  {

    // no mx records, ok to check domain

    if (!fsockopen($domain,25,$errno,$errstr,30))

    {

      return false;

    }

    else

    {

      return true;

    }

  }

  else

  {

    // mx records found

    foreach ($mxhosts as $host)

    {

      if (fsockopen($host,25,$errno,$errstr,30))

      {

        return true;

      }

    }

    return false;

  }

}

 

if (!isset($_REQUEST['email'])) {

    header( "Location: http://www.letsgohost.co.uk/contact.html" );

  }

  elseif (empty($email) || empty($message) || empty($name)) {

 

    header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );

    header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );

    header( "Cache-Control: no-cache, must-revalidate" );

    header( "Pragma: no-cache" );

 

  ?>

 

    <html>

    <head><title>Error</title></head>

    <body>

    <h1>Error</h1>

    <p>

    Oops, it appears you haven't filled in the form correctly. Please ensure ALL fields have been filled in correctly. Please use the BACK

    button in your browser and try again.

    </p>

    </body>

    </html>

 

    <?php

 

  }

 

else {

    mail($to, $subject, $MsgBody, $MsgHeader);

    header("Location: http://www.letsgohost.co.uk/thanks.html");

  }

 

if(!is_numeric($_POST['telephone'])){

  echo("Telephone must be numeric (numbers only)");

  }

 

  ?>

 

The form posts perfectly. The problem i have is when i add the function checkEmail.  This seems to overide the other validation and allows me to leave the email box blank? When i remove the function the script works fine and i have to put a value in the email box. Obviously the email validator isnt working right.

Any suggestions?

Thanks people.

 

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.