Author: Wulf_9
original autor: memberlist.php?mode=viewprofile&u=174156
based on http://www.phpbb.com/community/viewtopic.php?t=280755
based on http://www.phpbb.com/community/viewtopi ... &t=1392575
MOD Description: When a user signs up or edits their email address, this MOD will
attempt to verify it via the DNS MX records and a test SMTP session,
returning true or false as appropriate. In the event of failure, some
server responses are displayed if DEBUG is set to true in constants.php
Code: Select all
#
#-----[ OPEN ]------------------------------------------
# original autor: https://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=174156
# based on http://www.phpbb.com/community/viewtopic.php?t=280755
# based on http://www.phpbb.com/community/viewtopic.php?f=72&t=1392575
#
includes/functions_user.php
#
#-----[ FIND ]------------------------------------------
#
/**
* Check to see if email address is a valid address and contains a MX record
*
* @param string $email The email to check
*
* @return mixed Either false if validation succeeded or a string which will be used as the error message (with the variable name appended)
*/
#
#-----[ BEFORE, ADD ]------------------------------------------
#
/* +MOD: Live Email Validate (LEV)
*
* test SMTP mail delivery
*/
function probe_smtp_mailbox($email, $hostname)
{
global $config, $user, $phpEx;
@set_time_limit(30);
if ($connect = fsockopen($hostname, 25, $errno, $errstr, 15))
{
usleep(888);
$out = fgetss($connect, 1024);
if (preg_match('#^220#', $out))
{
fputs($connect, "HELO " . $config['server_name'] . "\r\n");
while (preg_match('#^220#', $out))
{
$out = fgetss($connect, 1024);
}
fputs($connect, "VRFY <" . $email . ">\r\n");
$verify = fgetss($connect, 1024);
fputs($connect, "MAIL FROM: <" . $config['board_email'] . ">\r\n");
$from = fgetss($connect, 1024);
fputs($connect, "RCPT TO: <" . $email . ">\r\n");
$to = fgetss($connect, 1024);
fputs($connect, "QUIT\r\n");
fclose($connect);
//$user->lang['Email_unverified'] = "Unverified E-Mail Adress";
//$user->lang['No_connection'] = "No Connection";
if (preg_match('#^250#', $from) && preg_match('#^250#', $to) && !preg_match('#^550#', $verify))
{
$result = false;
}
else
{
$result = "Unverified E-Mail Adress";
}
}
@fclose($connect);
}
else
{
$result = "No Connection";
}
return $result;
}
// Try to find an MX record that matches the hostname - Unix
function check_smtp_addr_unix($email)
{
list($username, $domain) = explode('@', $email);
if (checkdnsrr($domain, 'MX'))
{
getmxrr($domain, $mxhosts);
$result = probe_smtp_mailbox($email, $mxhosts[0]);
if (isset($result['error']) && ($result['error'] == false))
{
return $result;
}
for ($i = 1; $i < count($mxhosts); $i++)
{
$result = probe_smtp_mailbox($email, $mxhosts[$i]);
if (isset($result['error']) && ($result['error'] == false))
{
return $result;
}
}
return $result;
}
else
{
return (probe_smtp_mailbox($email, $domain));
}
}
// Try to find an MX record that matches the hostname - Win32
function check_smtp_addr_win($email)
{
list($username, $domain) = explode('@', $email);
exec("nslookup -type=MX $domain", $outputs);
foreach ($outputs as $hostname)
{
if (@strpos($domain, $hostname))
{
$result = probe_smtp_mailbox($email, $domain);
if ($result['error'] == false)
{
return $result;
}
}
}
if (isset($result))
{
return $result;
}
else
{
return (probe_smtp_mailbox($email, $domain));
}
}
/*
* -MOD: Live Email Validate (LEV)
*/
#
#-----[ FIND ]------------------------------------------
#
// Check MX record.
// The idea for this is from reading the UseBB blog/announcement. :)
if ($config['email_check_mx'])
{
list(, $domain) = explode('@', $email);
if (phpbb_checkdnsrr($domain, 'A') === false && phpbb_checkdnsrr($domain, 'MX') === false)
{
return 'DOMAIN_NO_MX_RECORD';
}
#
#-----[ AFTER, ADD ]------------------------------------
#
/* +MOD: Live Email Validate (LEV)
*
* global $HTTP_SERVER_VARS;
*/
global $request;
if ($request->is_set('SERVER_SOFTWARE', \phpbb\request\request_interface::SERVER))
{
$SERVER_SOFTWARE = $request->variable('SERVER_SOFTWARE', '', true, \phpbb\request\request_interface::SERVER);
}
else if (!isset($SERVER_SOFTWARE))
{
$server_software = $request->server('SERVER_SOFTWARE', '');
}
if (empty($server_software))
{
$server_software = $SERVER_SOFTWARE;
}
$system = preg_match("/Microsoft|Win32|IIS|WebSTAR|Xitami/", $server_software) ? $result = check_smtp_addr_win($email) : $result = check_smtp_addr_unix($email);
if ($result == true)
{
return $result;
}
/*
* -MOD: Live Email Validate (LEV)
*/
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM