这是wp_mail() WordPress中的函数。标头必须添加为数组,且不带尾随符\\n\\r 或类似。
示例
wp_mail(
    \'test@example.com\',
    \'Hello World!\',
    \'Just saying...\',
    array(
        \'MIME-Version: 1.0\',
        \'Content-type: text/html; charset=iso-8859-1\',
        sprintf(
            \'From: %s <no-reply@%s>\',
            get_bloginfo(\'name\'),
            site_url()
        ),
        sprintf( \'X-Mailer: PHP/%s\', phpversion() ),
     )
);
 要更改内容类型,还可以使用过滤器:
<?php
/* Plugin Name: WP Mail Content Type text/html */
function wpse_97789_mail_contenttype( $content_type )
{
    remove_filter( current_filter(), __FUNCTION__ );
    return \'text/html\';
}
// Then, whereever you need it, just add the filter before calling the function
// It removes itself after firing once
add_filter( \'wp_mail_content_type\', \'wpse_97789_mail_contenttype\' );
wp_mail(
    \'test@example.com\',
    \'Hello World!\',
    \'Just saying...\',
    array(
        \'MIME-Version: 1.0\',
        sprintf(
            \'From: %s <no-reply@%s>\',
            get_bloginfo(\'name\'),
            site_url()
        ),
        sprintf( \'X-Mailer: PHP/%s\', phpversion() ),
    )
);