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

Function Reference/wp mail


A function to send e-mail, similar to PHP's mail().

The default sender name is "WordPress" and the default sender email address is wordpress@yoursite.com. These may be changed by including a header:

From: "Example User" <email@example.com>

Optional filters 'wp_mail_from' and 'wp_mail_from_name' are run on the sender email address and name. The return values are reassembled into a 'from' address like '"Example User" <email@address.com>' If only 'wp_mail_from' returns a value, then just the email address will be used with no name.

The default content type is 'text/plain' which does not allow using HTML. You can set the content type of the email either by using the 'wp_mail_content_type' filter ( see example below), or by including a header like "Content-type: text/html". Be careful to reset 'wp_mail_content_type' back to 'text/plain' after you send your message, though, because failing to do so could lead to unexpected problems with e-mails from WP or plugins/themes.

The default charset is based on the charset used on the blog. The charset can be set using the 'wp_mail_charset' filter.


 <?php wp_mail$to$subject$message$headers$attachments ); ?> 


(string or array) (required) The intended recipient(s). Multiple recipients may be specified using an array or a comma-separated string.
Default: None
(string) (required) The subject of the message.
Default: None
(string) (required) Message content.
Default: None
(string or array) (optional) Mail headers to send with the message. For the string version, each header line (beginning with From:, Cc:, etc.) is delimited with a newline ("\r\n") (advanced)
Default: Empty
(string or array) (optional) Files to attach: a single filename, an array of filenames, or a newline-delimited string list of multiple filenames. (advanced)
Default: Empty


(bool) (required) Whether the email contents were sent successfully.
Default: None

A true return value does not automatically mean that the user received the email successfully. It just only means that the method used was able to process the request without any errors.


Basic usage example:

<?php wp_mail( 'me@example.net', 'The subject', 'The message' ); ?>

Add attachment and "from" header:

$attachments = array( WP_CONTENT_DIR . '/uploads/file_to_attach.zip' );
$headers = 'From: My Name <myname@example.com>' . "\r\n";
wp_mail( 'test@example.org', 'subject', 'message', $headers, $attachments );

Sending to multiple recipients:

$multiple_recipients = array(
$subj = 'The email subject';
$body = 'This is the body of the email';
wp_mail( $multiple_recipients, $subj, $body );

Switch to HTML formatted email (using wp_mail_content_type filter):

add_filter( 'wp_mail_content_type', 'set_html_content_type' );

$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';

wp_mail( $to, $subject, $body );

// Reset content-type to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

function set_html_content_type() {
	return 'text/html';

As an alternative, you can specify the Content-Type HTTP header in the $headers parameter:

$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to, $subject, $body, $headers );

Example using the array form of $headers:

// assumes $to, $subject, $message have already been defined earlier...

$headers[] = 'From: Me Myself <me@example.net>';
$headers[] = 'Cc: John Q Codex <jqc@wordpress.org>';
$headers[] = 'Cc: iluvwp@wordpress.org'; // note you can just use a simple email address

wp_mail( $to, $subject, $message, $headers );


  • A true return value does not automatically mean that the user received the email successfully.
  • For this function to work, the settings SMTP and smtp_port (default: 25) need to be set in your php.ini file.
  • The function is available after the hook 'plugins_loaded'.
  • The filenames in the $attachments attribute have to be filesystem paths.

Valid Address Formats

All email addresses supplied to wp_mail() as the $to parameter must comply with RFC 2822. Some valid examples:

  • user@example.com
  • user@example.com, anotheruser@example.com
  • User <user@example.com>
  • User <user@example.com>, Another User <anotheruser@example.com>

The same applies to Cc: and Bcc: fields in $headers, but as noted in the next section, it's better to push multiple addresses into an array instead of listing them on a single line. Either address format, with or without the user name, may be used.

Using $headers To Set "From:", "Cc:" and "Bcc:" Parameters

To set the "From:" email address to something other than the WordPress default sender (see #Description above), or to add "Cc:" and/or "Bcc:" recipients, you must use the $headers argument.

$headers can be a string or an array, but it may be easiest to use in the array form. To use it, push a string onto the array, starting with "From:", "Bcc:" or "Cc:" (note the use of the ":"), followed by a valid email address.

When you are using the array form, you do not need to supply line breaks ("\n" or "\r\n"). Although the function can handle multiple emails per line, it may simply be easier to push each email address separately onto the $headers array. The function will figure it out and will build the proper Mime header automagically. Just don't forget that each string you push must have the header type as the first part of the string ("From:", "Cc:" or "Bcc:")

Change Log

Since: 1.2.1

Source File

wp_mail() is located in wp-includes/pluggable.php.