[3.2][BETA] Live Email Validate (LEV)

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
orynider
Translator
Posts: 271
Joined: Wed Nov 16, 2005 12:48 pm
Location: Arad, România
Name: Florin-Ciprian Bodin
Contact:

[3.2][BETA] Live Email Validate (LEV)

Post by orynider »

MOD Name: Live Email Validate (LEV)
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
		


User avatar
jackennils
Registered User
Posts: 229
Joined: Mon Jun 01, 2009 7:48 pm

Re: [3.2][BETA] Live Email Validate (LEV)

Post by jackennils »

This is not an extension, I think.
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3732
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: [3.2][BETA] Live Email Validate (LEV)

Post by Kailey »

orynider, please see the 3.2 Extensions page for information about writing extensions. If you would like to request this be converted to an extension, I can move this to the Extension Requests forum - just let me know. ;)
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
orynider
Translator
Posts: 271
Joined: Wed Nov 16, 2005 12:48 pm
Location: Arad, România
Name: Florin-Ciprian Bodin
Contact:

Re: [3.2][BETA] Live Email Validate (LEV)

Post by orynider »

It's more a snipped then an extension and I see no way this functions can be moved to a extension in "ext/" folder since functions_user.php does not have a function holder class that we can extend from an extension.
Post Reply

Return to “phpBB Custom Coding”