Jump to content

[SOLVED] mail form with email validation


pixeltrace

Recommended Posts

guys,

 

any other simple mailform that has email and textfield validation there?

i currently have a mailform that is working on php4-5 only

 

but its not working on lower and higher version

specifically with the getmxrr syntax

 

below is my current code and i hope you can help me with this

since the current php that i am using is higher

<?php
include("validate.php");
$yname = $_POST['yname'];
$yemail = $_POST['yemail'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];

if ($yname=='' or $yemail=='' or $ycontact=='')  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }
if(!yemail_is_valid($yemail)) {
	 error ('Please use a valid Email Address');
}

$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $yemail\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";

$Header = $yemail;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function yemail_is_valid ($yemail) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_yemail_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>

 

thanks!

Link to comment
Share on other sites

Use this for text validation:

if ( !preg_match('/^[a-zA-Z\" "]*$/', $yname) ) 
   {      
    error('Name is not Valid.\\n'.
            'Please try again.');
      }

Repeat it for every text box u want to validate.

 

Use this for email validation:

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $yemail)){ 
  error("Invalid e-mail address");
}

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.