• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Register Email v1.1

AndyB

Well-known member
#1
Purpose:

The purpose of this thread is to provide additional information on the Register Email v1.0 add-on. To download and install this add-on please visit the following XenForo Resource:

http://xenforo.com/community/resources/register-email.2586/

Description:

This add-on will send an email to the admin with information about a new registration sign up. This add-on is typically used on forums which have new user registration moderation and allows the admin to gain additional information to help identify and easily remove spammers before their account is approved.

(Example email)

pic001.jpg

Key Features:
  • Email sent immediately after completion of registration
  • Shows all custom user fields (in the email)
  • Shows location based on IP address (in the email)
  • Fully phrased
Admin Options:

pic002.jpg
 

AndyB

Well-known member
#2
The directory structure with the core files highlighted.

library
--Andy
----RegisterEmail
------ControllerPublic
--------Register.php
----Listener.php
 

AndyB

Well-known member
#3
library/Andy/RegisterEmail/ControllerPublic/Register.php

PHP:
<?php

class Andy_RegisterEmail_ControllerPublic_Register extends XFCP_Andy_RegisterEmail_ControllerPublic_Register
{
    public function actionRegister()
    {
        $parent = parent::actionRegister();	
		
		if (!isset($errors))
		{
			// get userId
			$userId = XenForo_Visitor::getUserId();
			
			if ($userId > 0)
			{
				// get database
				$db = XenForo_Application::get('db');
				
				// get visitor data
				$visitor = XenForo_Visitor::getInstance();					
				
				//########################################
				// customFields
				//########################################
				
				// get customFields
				$visitor['customFields'];
				
				// get options from Admin CP -> Options -> Register Email -> Custom User Fields    
				$fields = XenForo_Application::get('options')->customUserField;					
				
				// get custom userfields data
				$customFieldsArray = XenForo_Application::arrayFilterKeys($visitor['customFields'], explode(',', $fields));
				
				//########################################
				// ip
				//########################################
				
				// decalre variable
				$ipAddress = '';								
				
				// get ip address
				$ipAddress = (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 0);
				
				// get country info
				$tags = get_meta_tags('http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=' . $ipAddress);
				
				// prepare $location variable
				$location = $tags['city'] . ', ' . $tags['region'] . ', ' . $tags['country'];
				
				//########################################
				// start message part 1
				//########################################
				
				// get options from Admin CP -> Options -> Register Email -> To Email Address    
				$emailTo = XenForo_Application::get('options')->emailTo;	
				
				// subject					
				$emailSubject = new XenForo_Phrase('new_registration_for') . ' ' . $visitor['username'];
				
// message1
$emailMessage1 = new XenForo_Phrase('user_name') . ': ' . $visitor['username'] . '
	
' . new XenForo_Phrase('userid') . ': ' . $userId . '

' . new XenForo_Phrase('email') . ': ' . $visitor['email'] . '

';
				//########################################
				// start message part 2
				//########################################
				
				$emailMessage2 = '';
				
				$fieldName = explode(",",$fields);
				
				// count number of custom userfields to display
				$count = count($fieldName);			
				
// message2
for ($i=0; $i<$count; $i++) 
{
	$emailMessage2 = $emailMessage2 . $fieldName[$i] . ': ' . $customFieldsArray[$fieldName[$i]] . '

';
					
}
				//########################################
				// start message part 3
				//########################################
				
				// get internal_data path
				$webRoot =  XenForo_Link::buildPublicLink('full:forums');
				
// message3
$emailMessage3 = new XenForo_Phrase('ip_address') . ': ' . $ipAddress . '

' . new XenForo_Phrase('country_determined_by_ip') . ': ' . $location . '

' . new XenForo_Phrase('edit_user') . ': ' . $webRoot . 'admin.php?users/' . $userId . '/edit
';
				// create message from parts
				$emailMessage = $emailMessage1 . $emailMessage2 . $emailMessage3;
		
				// get options from Admin CP -> Options -> Register Email -> Email From    
				$emailFrom = 'From: ' . XenForo_Application::get('options')->emailFrom; // aka headers
				
				// send email
				mail($emailTo,$emailSubject,$emailMessage,$emailFrom);				
			}	
		}
	
		return $parent;
	}
}

?>
 
Last edited:

AndyB

Well-known member
#4
library/Andy/RegisterEmail/Listener.php

PHP:
<?php

class Andy_RegisterEmail_Listener
{
    public static function Register($class, array &$extend)
    {
        if ($class == 'XenForo_ControllerPublic_Register')
        {
            $extend[] = 'Andy_RegisterEmail_ControllerPublic_Register';
        }
    }
}

?>