The Wp_mail () function is used to send mail, similar to the PHP Mail () function.
The default sender name is WordPress, and the sender's mailbox is similar to the wordpress@example.com one.
usage
Wp_mail ($to, $subject, $message, $headers, $attachments);
Parameters
$to
(String | Array) (required) recipients. Multiple recipients can use arrays or a comma-delimited string of mailboxes.
Default value: None
$subject
(string) (required) message headers.
Default value: None
$message
(string) (must) the content of the message.
Default value: None
$headers
(String | Array) (optional) message Headers information. Can be an array, or it can be a string separated by a carriage return (format: name:content).
Default value: Empty string
$attachments
(String | Array) (optional) message attachment. Multiple attachments can use arrays or strings separated by a carriage return.
Default value: Empty string
return value
(Boolean) Returns whether the message was sent successfully.
Example
The most basic message to send:
Wp_mail (' me@example.net ', ' the subject ', ' the message ');
Attachment and headers information:
$attachments = Array (wp_content_dir. '/uploads/file_to_attach.zip ');
$headers = ' from:my Name <myname@example.com> '. "RN";
Wp_mail (' test@example.org ', ' subject ', ' message ', $headers, $attachments);
Html Mail and send multiple mailboxes at once:
$multiple _to_recipients = Array (
' recipient1@example.com ',
' recipient2@foo.example.com '
)
wp_ Mail ($multiple _to_recipients, ' The subject ', ' <p>the <em>HTML</em> message</p> ', ' Content-type:text/html ');
Other
This function is located at: wp-includes/pluggable.php
troubleshoot messages that cannot be sent
the inability to send a message is a common problem with WordPress, typically because the server does not support the PHP mail () function, and there are usually two ways to fix it.
ps:wordpress Send mail must use the Wp_mail () function instead of calling the PHP SMTP class or other functions directly.
First, configure the server environment
If you are using a VPS, you can configure the server to enable the server to support the mail () function, according to each person's situation can be found by the search engine configuration method, here is not detailed.
Second, the use of SMTP
The second is to use SMTP to send mail, but also I recommend a method. SMTP is the use of other free mail service provider's server to send mail, so it is not easy to identify as spam in this way.
OK, let WordPress support SMTP recommended is the use of WP SMTP plug-in, installed in the background to configure your SMTP information, I use QQ mailbox.
Once configured, you can test to see if the configuration is successful at the bottom.
Plugin Home: https://wordpress.org/plugins/wp-smtp/