【问题标题】:Email Attachment in WordpressWordpress 中的电子邮件附件
【发布时间】:2025-12-05 17:55:02
【问题描述】:

我正在尝试在电子邮件中附加附件

 $attachments = array("http://localhost/sitename/wp-content/plugins/plugin_name/uploads/Bluehills_10.jpg");
   $headers = "From: $from <$from>" . "\r\n";
   $headers .= "Disposition-Notification-To: $from\r\n";
   $mail_sent = wp_mail("$to", "$subject", "$msg", $headers, $attachments );

使用此代码,我可以将电子邮件发送到正确的位置,但附件没有随电子邮件一起发送。

谁能告诉我可能是什么原因。

我稍后也想将多个文件作为附件发送。但文件不会是 zip 格式。

提前致谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    你使用了url 作为file/attachment 路径,但你应该使用机器的路径,你有这个:

    // A url (should be a path of your server)
    array("http://localhost/sitename/wp-content/plugins/plugin_name/uploads/Bluehills_10.jpg");
    

    但是,您应该使用服务器的路径,它可以是像/uploads/images/photo1.jpg 这样的相对路径。

    【讨论】:

    • 谢谢.. 我必须提供服务器的路径而不是 http url。
    • 很高兴它有帮助:-)