Is it possible to check an email from email via WordPress before an email is sent?

I'm working on a phpmailer plugin to send WordPress email via Amazon SES (which requires all emails to be verified). I'm using WordPress multisite and would like to set a different verified email per site.

So I would like to know if it is possible to get the variable that contains the from email to accomplish something similar to the following.

if(fromEmailVaribale == '[email protected]'){
 //Set from email
  $phpmailer->SetFrom('[email protected]', 'Example.com');
 //Set from email
  $phpmailer->SetFrom('[email protected]', 'Services Example.com');

1 Answer 1


In wp_mail() there are filters to adjust from address:

// Plugin authors can override the potentially troublesome default
$phpmailer->From     = apply_filters( 'wp_mail_from'     , $from_email );
$phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name  );

However they don't seem convenient for your needs because they don't provide access to mailer object at the same time.

You are probably better of using action hook further down

do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );

to check what $From field in it holds and adjust if necessary.

  • Thanks for responding I'm not too familiar on how to use the do_action_ref_array can you please explain it a bit further thanks
    – Oudin
    Commented Jun 15, 2013 at 15:31
  • @Oudin do you know how to work with action hooks in general? It's just slightly different form of do_action(), so use add_action() and get mailer object passed as argument to your callback.
    – Rarst
    Commented Jun 15, 2013 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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