wp_mail不在WordPress中发送附件

时间:2018-12-14 08:11:59

标签: wordpress email

我有此代码,它应该可以工作,发送电子邮件但没有附件。

$attachments = THEME_DIR . '/resources/img/emails/cropped.png';

$headers[] = 'Content-Type: text/html; charset=UTF-8';
$headers[] = 'From: Me Myself <me@example.net>';

wp_mail( 'test@example.org', 'subject', 'message', $headers, $attachments );

1 个答案:

答案 0 :(得分:0)

好吧,事实证明,您只需要使用ABSPATH。

$attachments = [
    ABSPATH . 'wp-content/themes/themename/resources/img/emails/cropped.png',
    ABSPATH . 'wp-content/themes/themename/resources/img/emails/facebook.png'
];

// Send the email and the invoice as an attachment.
wp_mail( 'test@email.com', 'New Invoice', 'Message body sent with attachment.', $headers, $attachments );

您还可以设置这些内容,或仅将它们包含在$ header中:

add_filter( 'wp_mail_content_type', function ( $content_type ) {
    return 'text/html';
} );

add_filter( 'wp_mail_from', 'yoursite_wp_mail_from' );
function yoursite_wp_mail_from( $content_type ) {
    return 'contact@yoursite.ca';
}

add_filter( 'wp_mail_from_name', 'yoursite_wp_mail_from_name' );
function yoursite_wp_mail_from_name( $name ) {
    return 'Your Site Inc.';
}
相关问题