当我使用我的函数发送邮件时,会创建一个额外的文件ATT00001.htm,并在执行代码时使用我的附件发送。 我该如何删除它? 它可以来自边界,但我没有到达,找到我的错误在哪里。
这是我的功能代码:
function mail_csv(){
$to = "to@to";
$from = "toto@toto";
$subject = "Test csv";
$separator = md5(time());
$eol = PHP_EOL;
$path = ABSPATH . 'wp-content/uploads/sites/'.get_current_blog_id().'/test_csv/';
$filename = "test_csv.csv";
$attachement = file_get_contents($path.$filename);
$attachement = chunk_split(base64_encode($attachement));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= 'Content-Type: multipart/mixed; boundary="'.$separator.'"';
$attached = "--" .$separator.$eol;
$attached .= 'Content-Type: text/csv; name="'.$filename.'"'.$eol;
$attached .= "Content-Transfer-Encoding: base64".$eol;
$attached .= 'Content-Disposition: attachment; filename="'.$filename.'"'.$eol.$eol;
$attached .= $attachement.$eol;
$attached .= "--".$separator."--";
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "Envoi d'un mail avec un fichier .csv en pièce jointe.".$eol;
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol.$attached.$eol;
if (mail($to, $subject, $body, $headers)) {
error_log("OK");
} else {
error_log("Erreur");
}
}