UPDATE 10.07.2013 10 years later some additions - see below
UPDATE 17.11.2003 Now it works with all providers...
==============================================
Hi,
I edited the function check_email() in functions.php to check if a email-address is valid or not... With this extended version of this function many invalid mail-entries will be rejected in registration-form
(but not all, because yahoo,...
).
I donīt know, if this mod works if you configured your 4images to use smtp. I think, ther must be some edits for this... Try it out and tell me your results (and your solution!
).
to do:
replace in .../4images/includes/functions.php:
function check_email($email) {
...
}
with:
function check_email($email) {
$state=0;
$helo_server=gethostbyaddr(gethostbyname($_SERVER["HTTP_HOST"]));
$from=$_SERVER["SERVER_ADMIN"];
if (preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i', $email) && !mailcheck($email, 2)) {
list($mailbox,$domain) = explode('@',$email,2);
// find preferred mailserver
if(getmxrr($domain,$mailhosts,$pref)){
array_multisort($mailhosts,$pref);
}
$mailhosts[]=$domain;
foreach($mailhosts as $hosts){
if($connection) {
fputs($connection, "QUIT\r\n");
fclose ($connection);
}
$mailserver = $hosts;
// Open an SMTP connection
$connection = @fsockopen ($mailserver, 25, $errno, $errstr, 1);
if (!$connection) continue;
socket_set_timeout($connection, 3);
$res=get_lines($connection);
if(checkres($res) != "220") continue;
// Introduce ourselves
$sendstring="EHLO ".$helo_server."\r\n";
fputs($connection,$sendstring);
$res=get_lines($connection);
if(checkres($res) != "250"){
$sendstring="HELO ".$helo_server."\r\n";
fputs($connection,$sendstring);
$res=get_lines($connection);
}
if(checkres($res) != "250") continue;
// Envelope from
$sendstring="MAIL FROM: <".$from.">\r\n";
fputs($connection,$sendstring);
$res=get_lines($connection);
if(checkres($res) != "250") continue;
// Envelope to
$sendstring="RCPT TO: <".trim($email).">\r\n";
fputs($connection,$sendstring);
$res=get_lines($connection);
if(checkres($res) != "250") continue;
/*
// Verify address
$sendstring="VRFY <".$mailbox.">\r\n";
print_res($sendstring,"Q");
fputs($connection,$sendstring);
$res=get_lines($connection);
print_res($res,"A");
if(checkres($res) != "250") continue;
// The message
$sendstring="DATA\r\n";
print_res($sendstring,"Q");
fputs($connection,$sendstring);
$res=get_lines($connection);
print_res($res,"A");
if(checkres($res) != "354") continue;
// Send To:, From:, Subject:, other headers, blank line, message, and finish
// with a period on its own line.
$sendstring="To: ".trim($_POST['p_email'])."\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n";
print_res($sendstring,"Q");
fputs($connection,$sendstring);
$res=get_lines($connection);
print_res($res,"A");
if(checkres($res) != "250") continue;
*/
// Say bye bye
$sendstring="QUIT\r\n";
fputs($connection,$sendstring);
$res=get_lines($connection);
if(checkres($res) != "250" && checkres($res) != "221") continue;
fclose ($connection);
// It worked! So break out of the loop which tries all the mail exchangers.
$state=1;
break;
}
}
return $state;
}
function mailcheck($Addr, $Level, $Timeout = 15000) {
// Valid Top-Level Domains
$gTLDs = "com:net:org:edu:gov:mil:int:arpa:aero:biz:coop:info:museum:name:";
$CCs = "ad:ae:af:ag:ai:al:am:an:ao:aq:ar:as:at:au:aw:az:ba:bb:bd:be:bf:".
"bg:bh:bi:bj:bm:bn:bo:br:bs:bt:bv:bw:by:bz:ca:cc:cf:cd:cg:ch:ci:".
"ck:cl:cm:cn:co:cr:cs:cu:cv:cx:cy:cz:de:dj:dk:dm:do:dz:ec:ee:eg:".
"eh:er:es:et:fi:fj:fk:fm:fo:fr:fx:ga:gb:gd:ge:gf:gh:gi:gl:gm:gn:".
"gp:gq:gr:gs:gt:gu:gw:gy:hk:hm:hn:hr:ht:hu:id:ie:il:in:io:iq:ir:".
"is:it:jm:jo:jp:ke:kg:kh:ki:km:kn:kp:kr:kw:ky:kz:la:lb:lc:li:lk:".
"lr:ls:lt:lu:lv:ly:ma:mc:md:mg:mh:mk:ml:mm:mn:mo:mp:mq:mr:ms:mt:".
"mu:mv:mw:mx:my:mz:na:nc:ne:nf:ng:ni:nl:no:np:nr:nt:nu:nz:om:pa:".
"pe:pf:pg:ph:pk:pl:pm:pn:pr:pt:pw:py:qa:re:ro:ru:rw:sa:sb:sc:sd:".
"se:sg:sh:si:sj:sk:sl:sm:sn:so:sr:st:su:sv:sy:sz:tc:td:tf:tg:th:".
"tj:tk:tm:tn:to:tp:tr:tt:tv:tw:tz:ua:ug:uk:um:us:uy:uz:va:vc:ve:".
"vg:vi:vn:vu:wf:ws:ye:yt:yu:za:zm:zr:zw:";
// The countries can have their own 'TLDs', e.g. mydomain.com.au
$cTLDs = "com:net:org:edu:gov:mil:co:ne:or:ed:go:mi:aero:biz:coop:info:museum:name:";
$fail = 0;
// Shift the address to lowercase to simplify checking and trim
$Addr = trim(strtolower($Addr));
// Check for spaces
if (ereg(" ", $Addr)) $fail = 1;
// Split the Address into user and domain parts
$UD = explode("@", $Addr);
if (sizeof($UD) != 2 || !$UD[0]) $fail = 1;
// Split the domain part into its Levels
$Levels = explode(".", $UD[1]); $sLevels = sizeof($Levels);
if (!$Levels[0] || !$Levels[1]) $fail = 1;
// Get the TLD, strip off trailing ] } ) > and check the length
$tld = $Levels[$sLevels-1];
$tld = ereg_replace("[>)}]$|]$", "", $tld);
if (strlen($tld) < 2
|| (strlen($tld) > 3 && !ereg(":$tld:", ":arpa:aero:coop:info:museum:name:"))) $fail = 1;
$Level--;
// If the string after the last dot isn't in the generic TLDs or country codes, it's invalid.
if ($Level && !$fail) {
$Level--;
if (!ereg($tld.":", $gTLDs) && !ereg($tld.":", $CCs)) $fail = 2;
}
// If it's a country code, check for a country TLD; add on the domain name.
if ($Level && !$fail) {
$cd = $sLevels - 2; $domain = $Levels[$cd].".".$tld;
if (ereg($Levels[$cd].":", $cTLDs)) { $cd--; $domain = $Levels[$cd].".".$domain; }
}
echo $fail;
return $fail;
} //Mailcheck
Have fun!
[EDITED by V@no]
this mod is missing get_lines() function, because of that it doesn't work.
[EDITED by effemmess]
Here are some functions I used in some scripts, also the missing get_lines() function. I donīt know if it now works, at that time it worked for me. But now I havenīt a 4images-system, so I canīt test it.
function get_lines($fp){
$res = "";
while($data = fgets($fp,515)) {
$res .= $data;
if(substr($data,3,1) == " ") { break; }
}
return $res;
}
function checkres($res){
return substr($res,0,3);
}
function print_res($res,$typus){
if ($typus=="A") {
printf ("<b>Antwort:</b><br>");
} elseif ($typus=="Q") {
printf ("<b>Frage:</b><br>");
}
printf ($res."<br />");
return;
}
Have fun!