WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am setting up a "built in" contact form that I need to pull the administrators email address from an external php page.

For instance, my form action="path/to/process_form.php"

Within that proces_form.php I have a few options set up.

$msg = "Form Contents: \n\n";
foreach ($this->fields as $key => $field)
    $msg .= "$key :  $field \n";

$to = 'static@email.com';
$subject = 'New Form Submission';
$from = $this->fields['email'];

My goal is to dynamicly grab the admin email address from this page and populate the $to = '' area.

Any help would be much much appreciated!

share|improve this question
What part of this question involves WordPress? – s_ha_dum Nov 28 '12 at 5:41

Basically what you're looking to do is create a separate page within a WordPress site that (I'm sort of guessing here) you're not creating within WordPress itself, but you want to pull WordPress data.

There's a "cheater" method and an officially sanctioned method to do what you want.

The "cheater" method is to call wp-load.php from your separate PHP file. This will load the WP database stuff and give you access to WP functions. Many people think this is easier, but I do not recommend it because it can cause problems in certain setups.

The official way to do it is to go from within WordPress itself. Specifically, by hooking the template_redirect action you can redirect any URL you like to whatever PHP file you want -- while still having access to WP because you're running from within WP.

Then use get_userdata() to fetch the User's email address.

share|improve this answer

You won't be able to include it without executing it, and it looks like that would be a problem.

Unless you can edit the "external php page" and set the variables in a more convenient way you are probably going to be stuck with reading the file and regex-ing the email out of it. The problem with that approach is that you don't have control of the file so it could change and your code would break. It could be memory intensive and slow as well. I'd only do it that way if I had to.

The best solution is to set the email value elsewhere, perhaps as a constant, and forget about trying to extract an email address. It would help to see the code for the "external php page".

share|improve this answer

How about this:

// Connect to WP 
global $wpdb;

$admin_email = get_option( 'admin_email' ); ?> 

$msg = "Form Contents: \n\n";
foreach ($this->fields as $key => $field)
    $msg .= "$key :  $field \n";

$to = $admin_email;
$subject = 'New Form Submission';
$from = $this->fields['email'];

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.