WP_MAIL:数组为$to-多个电子邮件,还是包含所有电子邮件ID的单个电子邮件?

时间:2013-05-02 作者:Debiprasad

如果我将使用wp\\u mail函数的$to参数的电子邮件ID数组,它会向所有这些电子邮件ID发送不同的电子邮件,还是会发送一封电子邮件,其中所有电子邮件ID都是“to”?

1 个回复
最合适的回答,由SO网友:fuxia 整理而成

可以,您可以使用收件人数组:

 * @param string|array $to Array or comma-separated list of email addresses to send message.
 * @param string $subject Email subject
 * @param string $message Message contents
 * @param string|array $headers Optional. Additional headers.
 * @param string|array $attachments Optional. Files to attach.
 * @return bool Whether the email contents were sent successfully.
 */
function wp_mail( $to, $subject, $message, $headers = \'\', $attachments = array() ) {

// …


    // Set destination addresses
    if ( !is_array( $to ) )
        $to = explode( \',\', $to );

    foreach ( (array) $to as $recipient ) {
        try {
            // Break $recipient into name and address parts if in the format "Foo <[email protected]>"
            $recipient_name = \'\';
            if( preg_match( \'/(.*)<(.+)>/\', $recipient, $matches ) ) {
                if ( count( $matches ) == 3 ) {
                    $recipient_name = $matches[1];
                    $recipient = $matches[2];
                }
            }
            $phpmailer->AddAddress( $recipient, $recipient_name);
        } catch ( phpmailerException $e ) {
            continue;
        }
    }
要发送不同的电子邮件,你必须打电话wp_mail() 多次。

结束

相关推荐