Home » Hooks » wp_mail_from

The wp_mail_from hook is a filter that allows developers to modify the email address that WordPress uses as the "From" address in outgoing emails. By default, this email address is set to the address of the WordPress site administrator.

This hook is particularly useful for developers who are building custom plugins or themes and need to change the sender email address to something more appropriate or relevant to their specific use case. For example, a developer might want to set the "From" address to a support email address for their company, or to a custom email address associated with their plugin or theme.

Here’s an example code snippet that demonstrates how to use the wp_mail_from filter to change the sender email address to something other than the default WordPress administrator email:

function my_custom_wp_mail_from( $original_email_address ) {
    // Change the "From" address to a custom email address
    $new_email_address = 'support@mycompany.com';
    return $new_email_address;

add_filter( 'wp_mail_from', 'my_custom_wp_mail_from' );

In this example, the my_custom_wp_mail_from function is defined to accept the original email address as a parameter, and then return a new email address that will be used as the "From" address for all outgoing WordPress emails. The add_filter function is then used to register the my_custom_wp_mail_from function as the filter that should be applied to the wp_mail_from hook.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.