Jump to content

Validating E-Mail Address (both Syntax and Domain)


telephonefield

Recommended Posts

Hi all,

 

I need some help with a simple PHP Mail Script that I have. I am by no means a coder but have been asked to make a script that will send an E-Mail after signing up for a newsletter. I struggled with finding a solution that checks E-Mail Syntax, but finally got it to work perfectly. Now, I have been asked to edit it so that the Script checks if the Address actually exists! Very hard for me to do on my own.

 

Here is what I have so far and I'd like to keep things as simple as they are, if that's at all possible.

 

<?php
  $newsletter_name = $_REQUEST['newsletter_name'] ;
  $newsletter_name = utf8_decode($newsletter_name);
  $newsletter_email = $_REQUEST['newsletter_email'] ;
  $header  = 'MIME-Version: 1.0' . "\r\n";
  $header .= 'Content-type: text/html; charset=utf-8' . "\r\n";

  
  if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $newsletter_email)) 
  { 
  
  mail( "[email protected]", "$newsletter_name signs up for Newsletter", "Name: " . $newsletter_name . "\r\n" . "E-mail: " . $newsletter_email, "From: $newsletter_email", $header );
    
header( "Location: http://www.google.com" );
}

else { 
  echo "Bitte eine gültige E-Mail Adresse eingeben."; 
}
  
  
  


?>

I found a plug-in kind of solution that should work perfectly but it gives me a PHP Error, mixed with the Echo it should throw back for the False Statement.  Here is my code now:

 

<?php

function checkEmail($newsletter_email) 
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $newsletter_email)) 
   {
      return FALSE;
   }

   list($Username, $Domain) = split("@",$newsletter_email);

   if(getmxrr($Domain, $MXHost)) 
   {
      return TRUE;
   }
   else 
   {
      if(fsockopen($Domain, 25, $errno, $errstr, 30)) 
      {
         return TRUE; 
      }
      else 
      {
         return FALSE; 
      }
   }
}



  $newsletter_name = $_REQUEST['newsletter_name'] ;
  $newsletter_name = utf8_decode($newsletter_name);
  $newsletter_email = $_REQUEST['newsletter_email'] ;
  $header  = 'MIME-Version: 1.0' . "\r\n";
  $header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
  
  
  
  
  if(checkEmail($newsletter_email) == FALSE) 
{
   echo "Bitte eine gültige E-Mail Adresse eingeben.";
} 
else 
{
   mail( "[email protected]", "$newsletter_name möchte den Newsletter abonnieren", "Name: " . $newsletter_name . "\r\n" . "E-mail: " . $newsletter_email, "From: $newsletter_email", $header );
    
header( "Location: http://www.google.com" );
}

  
  



?>

 

 

And here is my Error/Echo:

 

 

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/htdocs/w00828f0/newsletter_validating.php on line 18

 

Warning: fsockopen() [function.fsockopen]: unable to connect to doesntela.com:25 in /www/htdocs/w00828f0/newsletter_validating.php on line 18

Bitte eine gültige E-Mail Adresse eingeben.

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.