wp_mail_from
Filters the email address from which WordPress emails are sent.
add_filter( 'wp_mail_from', $callback, 10, 1 );
Description
Filters the sender email address used for emails sent by WordPress. Allows developers to dynamically change the default 'From' address, useful for customization or integrating with transactional email services.
Usage
add_filter( 'wp_mail_from', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter is not used by the `wp_mail_from` filter and is instead ignored.
Return Value
The filtered value.
Examples
add_filter( 'wp_mail_from', 'custom_wp_mail_from_address', 10, 1 );
/**
* Changes the default sender email address for WordPress emails.
*
* This function demonstrates how to modify the 'wp_mail_from' filter
* to use a specific email address for all outgoing emails from WordPress.
* This can be useful for branding or to ensure emails come from a
* dedicated address that's less likely to be flagged as spam.
*
* @param string $email The current sender email address.
* @return string The modified sender email address.
*/
function custom_wp_mail_from_address( $email ) {
// Replace '[email protected]' with your desired sender email address.
// Ensure this email address is configured correctly on your server for sending.
return '[email protected]';
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/includes/class.DisableEmailsPHPMailerMock.php:187
continue;
}
}
}
if ( $plugin->options['wp_mail_from'] ) {
$this->phpmailer->From = apply_filters( 'wp_mail_from', $this->phpmailer->From );
}
if ( $plugin->options['wp_mail_from_name'] ) {
$this->phpmailer->FromName = apply_filters( 'wp_mail_from_name', $this->phpmailer->FromName );
}
if ( $plugin->options['wp_mail_content_type'] ) {
$this->phpmailer->ContentType = apply_filters( 'wp_mail_content_type', $this->phpmailer->ContentType );
}