簡體   English   中英

在 PHP 中通過郵件發送附件

[英]Send attachment via mail in PHP

if(isset($input->csvrequest)){

  $mailsubject= $input->mailsubject;
  $mailbody= $input->mailbody;
  $mailto= $input->mailto;
  $to = $mailto; 
  $mail_subject = $mailsubject;
  $mail_message = $mailbody;

  $headers = "From: Test <support@test.com>\r\n";
  $headers .= "Reply-To: support@test.com\r\n";
  $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
  $headers .= "X-Priority: 0\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=win-1251\r\n";

  wp_mail($to, $mail_subject, $mail_message, $headers);

  add_filter('wp_mail_content_type', create_function('', 'return "text/html"; '));
  $arr["error"] = "Email Sent";

}

所以,這段代碼正在為我發送郵件。 實際上我想用這封郵件向用戶發送一個附件。(例如:file.csv)

假設您已在 wordpress 媒體庫中上傳了“file.csv”。 現在,設置附件變量並傳遞給 wp 郵件 function 就是這樣。 已開始發送附件。

    $mail_attachment = array(WP_CONTENT_DIR . '/uploads/2021/03/file.csv');
    wp_mail($to, $mail_subject, $mail_message, $headers, $mail_attachment);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM