GetSimple Support Forum

Full Version: Get admin email
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I get the admin e-mail inside a plugin php?

The same entered during install, and seen on Settings

Thanks.

-- Edit --

If someone looks for this function on the future, here it is:

PHP Code:
/*
 * Return email of the first GS user found
 * @return string
 */

function simple_c_default_email() {
  
$files scandir(GSUSERSPATH);
  foreach (
$files as $filename) {
    if (
preg_match("#\.xml$#"$filename)) {
      
$data getXML(GSUSERSPATH $filename);
      return 
$data->EMAIL;
    }
  }
  return 
"";

This function is from Simple ©ontact plugin: http://get-simple.info/forums/showthread...7#pid44287
This data is stored in /data/users/admin.xml so you can pull the email address from there.
Yes, but the name of the file is dynamic, the username isn't necessarily "admin"

I was trying something like this:

PHP Code:
function admin_email()
{
    
$admin_file scandir(GSUSERSPATH1);
    
$data getXML($admin_file[0]);
    return 
$data->EMAIL;
}

$xml->addChild('RECIPIENT_EMAIL'admin_email()); 

It returns a blank page though

Edit:

My second try, didn't work neither

PHP Code:
<?php
        $dir 
GSUSERSPATH;

        
$dh  opendir($dir);
        while (
false !== ($filename readdir($dh))) {
            
$files[] = $filename;
        }

        
rsort($files);
        
print_r($files);
        
$xml=simplexml_load_file($files[0]);

        echo 
$xml->email "<br>";
    
?>
Maybe with:

Code:
global $EMAIL;
// ... then use the $EMAIL variable
(2014-07-11, 23:27:50)Carlos Wrote: [ -> ]Maybe with:

Code:
global $EMAIL;
// ... then use the $EMAIL variable

Sorry, I didn't understand your answer, can you explain it a little further please?

Thanks
you did not specifcy from frontend or backend ?
Logged in user, or any arbitrary user email ?
There is no such thing as "admin" in getsimple.

PHP Code:
$user  'admin';
$file  _id($user) .'.xml';
$data  getXML(GSUSERSPATH $file);
$email = (string)$data->EMAIL
I think that the global $EMAIL variable contains the current (logged in) user name.

However, I hadn't realized you said this:
(2014-07-11, 07:17:11)lukinhasb Wrote: [ -> ]The same entered during install, and seen on Settings

If there are several users in the site, you cannot know which one did the install (or if it still exists)
(2014-07-12, 00:44:54)shawn_a Wrote: [ -> ]you did not specifcy from frontend or backend ?
Logged in user, or any arbitrary user email ?
There is no such thing as "admin" in getsimple.

PHP Code:
$user 'admin';
$file            _id($user) .'.xml';
$data         getXML(GSUSERSPATH $file);
$email                $data->EMAIL

I'm sorry, it's from the backend. Assuming there will be only one user, and I don't know his username, how can I retrieve his e-mail?

(I'm trying to do a website that can be set up in less than 5 minutes, and the contact form should be pre-configured with the e-mail inserted during Get-Simple installation, to save time. I'll block the add/remove user functions)
global $EMAIL like carlos said probably does not exists but you can use.

$datau->EMAIL

there is
get_site_email($echo=true);
But it uses global $EMAIL, but i do not see if ever getting set in common.php so i am not sure it works.
It is also only available on front end pre 3.4
new issue (https://github.com/GetSimpleCMS/GetSimpleCMS/issues/868)
so nevermind

use
$USR_email = trim(stripslashes($datau->EMAIL));
Sorry for my misleading reply. As Shawn says $EMAIL does not currently work. That was in GS 2.x

If you want to get the current (logged in) user's email you can do as Shawn suggests above.

However if you want a main email address that also works for frontend anonymous users, I suggest you define it in gsconfig.php, changing:
Code:
#define('GSFROMEMAIL', 'noreply@get-simple.info');
by:
Code:
define('GSFROMEMAIL', 'youremail@domain.com');
and then check this constant in your code like, for example:
Code:
if (defined('GSFROMEMAIL')) {
    $email = GSFROMEMAIL;
} else {
    $email = 'someemail@domain.com';
}
I hope you get the idea.
Just be aware that this is the sending email used for sending emails, and it could be a noreply@ etc. which would go nowhere.

I wonder if $EMAIL got removed.
Yup, another wrong answer... definitely not my day, sorry.
Thanks for all your help guys.

It's solved though, found this code on Simple ©ontact plugin: http://get-simple.info/forums/showthread...7#pid44287
PHP Code:
/*
 * Return email of the first GS user found
 * @return string
 */

function simple_c_default_email() {
  
$files scandir(GSUSERSPATH);
  foreach (
$files as $filename) {
    if (
preg_match("#\.xml$#"$filename)) {
      
$data getXML(GSUSERSPATH $filename);
      return 
$data->EMAIL;
    }
  }
  return 
"";

That is some aweful code