WordPress.org

Codex

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

Plugin API/Filter Reference/wp mail

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) A compacted array of wp_mail() arguments, including the "to" email, subject, message, headers, and attachments values.
Default: array()

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 File

wp_mail is located in wp-includes/pluggable.php

Related