📅  最后修改于: 2023-12-03 14:48:34.558000             🧑  作者: Mango
wp_mail
wp_mail
is a powerful function in WordPress that allows you to send emails. It is a core function provided by WordPress itself, making it easy to incorporate email functionality into your plugin or theme.
The function signature for wp_mail
is as follows:
wp_mail( string|array $to, string $subject, string $message, string|array $headers = '', string|array $attachments = '' )
Let's take a closer look at each parameter:
$to
(required): The recipient(s) of the email. This can be a single email address or an array of multiple addresses.$subject
(required): The subject line of the email.$message
(required): The content of the email.$headers
(optional): Additional headers to include in the email. This can be a string or an array.$attachments
(optional): File attachments to include with the email. This can be a string or an array.To send an email using wp_mail
, you can simply call the function and pass in the required parameters. Here's an example:
$to = 'john@example.com';
$subject = 'Hello from WordPress!';
$message = 'This is a test email sent using wp_mail.';
$headers = array(
'From: Your Name <yourname@example.com>',
'Reply-To: Your Name <yourname@example.com>',
'Content-Type: text/html; charset=UTF-8'
);
// Send the email
wp_mail( $to, $subject, $message, $headers );
To format code snippets in markdown, you can enclose the code within triple backticks (```). For example:
```php $to = 'john@example.com'; $subject = 'Hello from WordPress!'; $message = 'This is a test email sent using wp_mail.';
// Send the email wp_mail( $to, $subject, $message ); ```
This will render the code snippet in a nicely formatted manner, making it easier to read and understand.
wp_mail
provides a convenient way to send emails within your WordPress projects. By understanding its function signature and proper usage, you can leverage this powerful function to incorporate email functionality seamlessly.