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
https://forums.phpfreaks.com/topic/41226-solved-mail-form-with-email-validation/
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");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.