WordPress.org

Ready to get started?Download WordPress

Codex

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

Plugin API/Filter Reference/wp mail

Contents

Description

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.

Parameters

$args
(array) (required) (to,subject,message,headers,attachments)
Default: None

Examples

add_filter( 'wp_mail', 'my_wp_mail_filter' );
function my_wp_mail_filter( $args ) {
	
	$new_wp_mail = array(
		'to'          => $args['to'],
		'subject'     => $args['subject'],
		'message'     => $args['message'],
		'headers'     => $args['headers'],
		'attachments' => $args['attachments']
	);
	
	return $new_wp_mail;
}

Notes

$attachments should be an array. If it is not, it will be converted to one by the wp_mail function after the filter.

Change Log

Since: Version 2.2

$attachments argument added in Version 2.7

Source Files

wp_mail is located in wp-includes/pluggable.php

Related