Codex tools: Log in
Contents |
Send 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 overridden by including a header like:
From: "Example User" <email@example.com>
Then, the optional hooks '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".
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 ); ?>
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.
<?php wp_mail('me@example.net', 'The subject', 'The message'); ?>
<?php
$attachments = array(WP_CONTENT_DIR . '/uploads/file_to_attach.zip');
$headers = 'From: My Name <myname@mydomain.com>' . "\r\n";
wp_mail('test@test.com', 'subject', 'message', $headers, $attachments);
?>
<?php
add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
wp_mail('me@example.net', 'The subject', '<p>The <em>HTML</em> message</p>');
?>
A true return value does not automatically mean that the user received the email successfully.
For this function to work, you need the following:SMTP and smtp_port need to be set in your php.inisendmail_from setting in php.ini, or pass it as an additional header.wp_mail() is located in wp-includes/pluggable.php.