我无法在wp_mail函数中发送附件文件

时间:2014-05-31 04:36:25

标签: php wordpress

我尝试使用wp_mail函数发送包含附件的邮件,但该邮件已成功发送但未发送附件。请帮助我。 我的代码如下。

$filename = wp_get_attachment_metadata($attchment_id);//Here media file attchment id
       $to = get_user_meta($result->user_id,'billing_email',true);//email id
       $subject = $result->msg_title;//Subject
       $message = $result->msg_body;//HTML message text
       $attachments = array(WP_CONTENT_DIR.'/'.$filename['file'] );//I also try with ABSPATH
       $headers[] = 'Content-Type: text/html; charset=UTF-8';
       $headers[] = 'From: Wordpress ' . "\r\n";
       $sendmail = wp_mail($to, $subject, $message,$headers,$attachments);

1 个答案:

答案 0 :(得分:0)

下面的代码可以帮助您,

<?php
    $attachments = array( WP_CONTENT_DIR . '/uploads/file_to_attach.zip' );
    $headers = 'From: My Name <myname@example.com>' . "\r\n";
    wp_mail('test@example.org', 'subject', 'message', $headers, $attachments );
?>

有关详情,请参阅http://codex.wordpress.org/Function_Reference/wp_mail