WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/wp mail from

Description

The wp_mail_from filter modifies the "from email address" used in an email sent using the wp_mail function. When used together with the 'wp_mail_from_name' filter, it creates a from address like "Name <email@address.com>". The filter should return an email address.

Parameters

$from_email
(string) (required) The "from" email address
Default: None

Examples

add_filter( 'wp_mail_from', 'custom_wp_mail_from' );
function custom_wp_mail_from( $original_email_address ) {
	//Make sure the email is from the same domain 
	//as your website to avoid being marked as spam.
	return 'webmaster@mydomainname.com';
}

It is not necessary to call another method if you can use anonymous functions (PHP 5.3.0+):

add_filter( 'wp_mail_from', function( $email ) {
	return 'webmaster@mydomainname.com';
});

Notes

  • To avoid your email being marked as spam, it is highly recommended that your "from" domain match your website.
  • Some hosts may require that your "from" address be a legitimate address.
  • If you apply your filter using an anonymous function, you cannot remove it using remove_filter().

Change Log

Since: Version 2.2

Source File

wp_mail_from is located in wp-includes/pluggable.php

Related