WordPress 中文文档

Function Reference/wp mail

出自WordPress Chinese 中文文档

跳转到: 导航, 搜索

目录

Description

Sends an email.

Usage

%%% ?php wp_mail( $to, $subject, $message, $headers, $attachments ); ? %%%

Parameters

tt$to/tt
(string) (required) The intended recipient(s) of the message.
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter

The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

tt$subject/tt
(string) (required) The subject of the message.
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter

The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

tt$message/tt
(string) (required) Message content.
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter

The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

tt$headers/tt
(string) (optional) Mail headers to send with the message. (advanced)
Default: Emptynoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter

The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

tt$attachments/tt
(array) (optional) Files to attach. (advanced)
Default: Emptynoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter

The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

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:ul liSettings codeSMTP/code and codesmtp_port/code need to be set in your php.ini/li liAlso, either set the codesendmail_from/code setting in php.ini, or pass it as an additional header./li /ul

Related

includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 已侦测回归模板: Template:Message /pre

Result

已侦测回归模板: Template:Message

/noinclude includeonlydiv style=clear:both; background-color:#FAEBD7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;This page is marked as incomplete. You can help Codex by expanding it./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 已侦测回归模板: Template:Message /pre

Result

已侦测回归模板: Template:Message

/noinclude

wordpress