Page 1 of 1
Request: Restrict users to specific email domain
Posted: Fri Jun 05, 2009 10:07 pm
by Amphicar770
/*************************************
Title:
Version:
Author:
Demo:
Download:
Website:
Short description:
*************************************/
Hi all,
just install Hesk and am incredibly impressed.
On thing I would like to be able to do is to limit users to email addresses within my email domain. Thus, if the email address does not end with "@mycompany.com" the user gets a warning message and either has to enter an "@mycompany.com" address or they can go no further.
Thanks,
Mike
Posted: Sat Jun 06, 2009 8:12 am
by Klemen
Try this:
- open file "common.inc.php" (inside "inc" folder) in Notepad or Wordpad
- find this code (lines 202-211):
Code: Select all
if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$address))
{
return $address;
}
if ($required) {
hesk_error($error);
} else {
return '';
}
Change it to:
Code: Select all
if (strpos($address,'@yourcompany.com'))
{
return $address;
}
if ($required) {
hesk_error('Sorry, you need a @yourcompany.com address to continue!');
} else {
return '';
}
Didn't test it though, let us know if it works.
Posted: Mon Jun 08, 2009 3:46 am
by Amphicar770
It looks like it is restricting the domain but it is not displaying the error message as defined. Instead, user sees:
"Please enter a valid e-mail address"
Thanks.
Posted: Mon Jun 08, 2009 8:39 am
by Klemen
You can change the text in the language file (inside "language" folder, open it in Notepad).
Posted: Fri Jun 26, 2009 2:57 pm
by Amphicar770
Yes, my bad! That fixed it.
I will post as a seperate request, but I am thinking that maybe a better way to handle this is to simply turn off email notifications to the visitor.
Re: Request: Restrict users to specific email domain
Posted: Wed May 16, 2012 6:45 pm
by JFMichaud
As on 2.3 version is there a way to do the same...
ie: the option have changed as it looks to be on line 990 an on...
i wanna have only 2 possible option @mydomain.com and @sub.mydomain.com
Thanks
Re: Request: Restrict users to specific email domain
Posted: Thu May 17, 2012 7:20 am
by Klemen
Replacing
with this (twice in the code!) should work:
Code: Select all
'/(@domain\.com|@sub\.domain\.com)$/'
Any valid (sub)domains should be within ( ) separated by a |
Instead of . and - use \. and \-
Examples:
Code: Select all
'/(@domain\.com)$/'
'/(@domain\.com|@sub\.domain\.com)$/'
'/(@domain\.com|@sub\.domain\.com|@some\-long\-domain\.com)$/'
Re: Request: Restrict users to specific email domain
Posted: Thu May 17, 2012 12:15 pm
by JFMichaud
Nice...
I've done in common.inc.php
Code: Select all
if ( ! preg_match('/([\w\-]+\@domain\.com|[\w\-]+\@sub\.domain\.com)$/',$v))
Code: Select all
if (preg_match('/([\w\-]+\@domain\.com|[\w\-]+\@sub\.domain\.com)$/',$address))
Thanks
Re: Request: Restrict users to specific email domain
Posted: Mon Apr 23, 2018 12:57 pm
by JohnJ
Hello,
is this also posible in 2.7.6?
thx.
Re: Request: Restrict users to specific email domain
Posted: Mon Apr 23, 2018 3:24 pm
by Klemen
The code changed a bit, but still doable; in inc/common.inc.php find
Code: Select all
/* Character not valid in local part unless local part is quoted */
and just ABOVE/BEFORE that code add
Code: Select all
// List of email domains accepted. Everything after @
$accept_domains = array(
'example.com',
'sub.example.com',
'another-example.com',
);
// Only accept emails from domains listed above
if ( ! in_array(strtolower($domain), array_map('strtolower', $accept_domains)) )
{
return false;
}
I
strongly recommend you use a powerful text editor to make changes, such as the free
Notepad++ (some editors, including Windows Notepad, won't save PHP files in the correct encoding).
Re: Request: Restrict users to specific email domain
Posted: Tue Apr 24, 2018 10:07 am
by JohnJ
Thank you so much!