|
|
|
| Title : |
Clever Email Validation Function - E-Mail validation function with an eregi expression and socket connection. |
| Categories : |
Email, PHP, Regexps |
 ifsnow *^^* |
| Date : |
Feb 14th 2001 |
| Grade : |
5 of 5 (graded 3 times) |
| Viewed : |
10438 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by ifsnow *^^* |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<?
/*
==================================================================
=====
ifsnow's email valid check function SnowCheckMail Ver 0.1
funtion SnowCheckMail ($Email,$Debug=false)
$Email : E-Mail address to check.
$Debug : Variable for debugging.
* Can use everybody if use without changing the name of function.
Reference : O'REILLY - Internet Email Programming
HOMEPAGE : http://www.hellophp.com
ifsnow is korean phper. Is sorry to be unskillful to English. *^^*;;
==================================================================
======= */
function SnowCheckMail($Email,$Debug=false)
{
global $HTTP_HOST;
$Return =array();
// Variable for return.
// $Return[0] : [true|false]
// $Return[1] : Processing result save.
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email))
{
$Return[0]=false;
$Return[1]="${Email} is E-Mail form that is not right.";
if ($Debug) echo "Error : {$Email} is E-Mail form that is not right.<br>";
return $Return;
}
else if ($Debug) echo "Confirmation : {$Email} is E-Mail form that is not right.<br>";
// E-Mail @ by 2 by standard divide. if it is $Email this "lsm@ebeecomm.com"..
// $Username : lsm
// $Domain : ebeecomm.com
// list function reference : http://www.php.net/manual/en/function.list.php
// split function reference : http://www.php.net/manual/en/function.split.php
list ( $Username, $Domain ) = split ("@",$Email);
// That MX(mail exchanger) record exists in domain check .
// checkdnsrr function reference : http://www.php.net/manual/en/function.checkdnsrr.php
if ( checkdnsrr ( $Domain, "MX" ) ) {
if($Debug) echo "Confirmation : MX record about {$Domain} exists.<br>";
// If MX record exists, save MX record address.
// getmxrr function reference : http://www.php.net/manual/en/function.getmxrr.php
if ( getmxrr ($Domain, $MXHost)) {
if($Debug) {
echo "Confirmation : Is confirming address by MX LOOKUP.<br>";
for ( $i = 0,$j = 1; $i < count ( $MXHost ); $i++,$j++ ) {
echo " Result($j) - $MXHost[$i]
<BR>";
}
}
}
// Getmxrr function does to store MX record address about $Domain in arrangement form
to $MXHost.
// $ConnectAddress socket connection address.
$ConnectAddress = $MXHost[0];
}
else {
// If there is no MX record simply @ to next time address socket connection do .
$ConnectAddress = $Domain;
if ($Debug) echo "Confirmation : MX record about {$Domain} does not exist.<br>";
}
// fsockopen function reference : http://www.php.net/manual/en/function.fsockopen.php
$Connect = fsockopen ( $ConnectAddress, 25 );
// Success in socket connection
if ($Connect)
{
if ($Debug) echo "Connection succeeded to {$ConnectAddress} SMTP.<br>";
// Judgment is that service is preparing though begin by 220 getting string after
connection .
// fgets function reference : http://www.php.net/manual/en/function.fgets.php
if ( ereg ( "^220", $Out = fgets ( $Connect, 1024 ) ) ) {
// Inform client's reaching to server who connect.
fputs ( $Connect, "HELO $HTTP_HOST\r\n" );
if ($Debug) echo "Run : HELO $HTTP_HOST<br>";
$Out = fgets ( $Connect, 1024 ); // Receive server's answering cord.
// Inform sender's address to server.
fputs ( $Connect, "MAIL FROM: <{$Email}>\r\n" );
if ($Debug) echo "Run : MAIL FROM: <{$Email}><br>";
$From = fgets ( $Connect, 1024 ); // Receive server's answering cord.
// Inform listener's address to server.
fputs ( $Connect, "RCPT TO: <{$Email}>\r\n" );
if ($Debug) echo "Run : RCPT TO: <{$Email}><br>";
$To = fgets ( $Connect, 1024 ); // Receive server's answering cord.
// Finish connection.
fputs ( $Connect, "QUIT\r\n");
if ($Debug) echo "Run : QUIT<br>";
fclose($Connect);
// Server's answering cord about MAIL and TO command checks.
// Server about listener's address reacts to 550 codes if there does not exist
// checking that mailbox is in own E-Mail account.
if ( !ereg ( "^250", $From ) || !ereg ( "^250", $To )) {
$Return[0]=false;
$Return[1]="${Email} is address done not admit in E-Mail server.";
if ($Debug) echo "{$Email} is address done not admit in E-Mail server.<br>";
return $Return;
}
}
}
// Failure in socket connection
else {
$Return[0]=false;
$Return[1]="Can not connect E-Mail server ({$ConnectAddress}).";
if ($Debug) echo "Can not connect E-Mail server ({$ConnectAddress}).<br>";
return $Return;
}
$Return[0]=true;
$Return[1]="{$Email} is E-Mail address that there is no any problem.";
return $Return;
}
?>
http://mailzine.hellophp.com/test/mail_example_en.html |
|
| email validator check checker email e-mail email address Categories : PHP, Email, Regexps | | | making links from text Categories : PHP, Regexps, Email | | | validateEmail 2.0 - upgraded version of the old validateEmail function used to validate email
addresses via SMTP and regex. Categories : Email, Regexps, PHP | | | Check if a file exists on a remote FTP server with PHP Categories : PHP, FTP, Regexps | | | Show Source with Line Numbers Categories : PHP, Regexps, Filesystem | | | Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS) | | | Email a user with out exposing email address Categories : PHP, Databases, MySQL, Email | | | Simple way to replace a variable value in a .conf (.ini) file using a
webbrowser - the first stage of a complete universal configuration editor Categories : PHP, Regexps, Code Editors, Filesystem | | | ereg -- Regular expression match Categories : PHP, PHP Functions, Regexps | | | Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | | | Broadcast HTML Email Categories : PHP, Email, MySQL, Databases | | | BBCode Formatting String Categories : PHP, HTML, Regexps, Arrays | | | A web-based php3 IMAP email client supporting address books, attachements (downloading and sending), LDAP searching, and much much more. Categories : Email, PHP, LDAP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | I need a trim function/regexp that will trim all " " from the ends of a string. Categories : Regexps, PHP, Strings | |
|
|
|