apply_filters( 'wp_mail', array $args )

Filters the wp_mail() arguments.


Parameters

$args array
Array of the wp_mail() arguments.
  • tostring|string[]
    Array or comma-separated list of email addresses to send message.
  • subjectstring
    Email subject.
  • messagestring
    Message contents.
  • headersstring|string[]
    Additional headers.
  • attachmentsstring|string[]
    Paths to files to attach.

Top ↑

More Information

  • The wp_mail filter hook allows you to filter the arguments that are passed to the wp_mail() function. The arguments for wp_mail() are passed through the filter as an array.
  • $attachments should be an array. If it is not, it will be converted to one by the wp_mail function after the filter.

Top ↑

Source

File: wp-includes/pluggable.php. View all references

$atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );


Top ↑

Changelog

Changelog
Version Description
2.2.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Aurovrata Venet

    modify the recipient of the email

    add_filter('wp_mail','redirect_mails', 10,1);
    function redirect_mails($args){
        $to = $args['to'];
        //$args['subject']
        //$args['message']
        //$args['headers']
        //$args['attachments']
        $user = get_user_by( 'email', $to);
        $_role = get_user_meta($user->ID, 'my_custom_role', true);
        if ($role == 'opportunity-owner') {
          $test_mentor_email = get_option('test_mentor_email');
          if ($test_mentor_email != '') {
            $to = $test_mentor_email;
          }
        }
        $args['to']=$to;
        return $args;
      }

You must log in before being able to contribute a note or feedback.