Codex

Function Reference/wp mail

Contents

Description

Sends an email.

Usage

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

Parameters

$to
(string) (required) The intended recipient(s) of the message.
Default: None
$subject
(string) (required) The subject of the message.
Default: None
$message
(string) (required) Message content.
Default: None
$headers
(string) (optional) Mail headers to send with the message. (advanced)
Default: Empty
$attachments
(array) (optional) Files to attach. (advanced)
Default: Empty

Examples

 <?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);
?>

Notes

The default content type is 'text/plain' which does not allow using HTML. However, you can set the content type of the email by using the 'wp_mail_content_type' filter.

A true return value does not automatically mean that the user received the email successfully.

For this function to work, you need the following:
  • Settings SMTP and smtp_port need to be set in your php.ini
  • Also, either set the sendmail_from setting in php.ini, or pass it as an additional header.

Related

See also index of Function Reference and index of Template Tags.
This page is marked as incomplete. You can help Codex by expanding it.