Analysis of PHP function usage related to email sending using WordPress

Source: Internet
Author: User
This article mainly introduces the usage of PHP functions related to sending email via WordPress. It also describes how to solve common failures in sending emails. For more information, see wp_mail () the function is used to send emails, similar to the mail () function in PHP.

The default sender name is WordPress, and the sender mailbox is similar to a

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



(String | array) (required) recipient. Multiple recipients can use arrays or strings separated by commas.

Default value: None

$ Subject

(String) (required) Mail title.

Default value: None

$ Message

(String) (required) the content of the email.

Default value: None

$ Headers

(String | array) (optional) mail Headers information. It can be an array or a string separated by carriage return (format: name: content ).

Default value: Null string

$ Attachments

(String | array) (optional) email attachment. Multiple attachments can use arrays or strings separated by carriage return.

Default value: Null string

Return value

(Boolean) whether the email is successfully sent.


Basic email sending:

wp_mail( '', 'The subject', 'The message' );

Attachment and headers information:

$attachments = array( WP_CONTENT_DIR . '/uploads/' );$headers = 'From: My Name 
  ' . "rn";wp_mail( '', 'subject', 'message', $headers, $attachments );

Html mail and multiple mailboxes sent at a time:

$multiple_to_recipients = array(  '',  '')wp_mail( $multiple_to_recipients, 'The subject', '

The HTML message

', 'Content-Type: text/html' );


This function is located in: wp-uplodes/pluggable. php

Solve the problem that emails cannot be sent
Failure to send emails is a common problem in WordPress. Generally, the server does not support the mail () function in PHP. There are two solutions.

PS: WordPress must use the wp_mail () function to send emails, rather than directly calling the php smtp class or other functions.

1. configure the server environment

If you are using VPS, you can configure the server to allow the server to support the mail () function. you can use the search engine to find the configuration method based on your situation.

II. use SMTP

The second method is to use SMTP to send emails, which is also a recommended method. SMTP is to use the servers of other free email service providers to send emails. Therefore, it is not easy to identify emails as spam.

We recommend that you use the wp smtp plug-in for WordPress support. after installation, configure your SMTP information in the background. I use QQ mail.

After configuration, you can test whether the configuration is successful.

Plug-in home:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.