亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過 php 郵件發送時無法為 ics 文件設置名稱

通過 php 郵件發送時無法為 ics 文件設置名稱

PHP
千萬里不及你 2023-09-22 14:43:30
當我使用 mail() 函數發送文件時,我試圖設置文件的名稱,我發送了它,但在 gmail 中我收到的是沒有擴展名的無名文件。有人可以幫我嗎?<?php$temp = tmpfile();fwrite($temp, $ical);rewind($temp);$to_email = '[email protected]';$subject = 'Testing PHP Mail';$message = 'Hola caracola';$from_email = '[email protected]';$path = stream_get_meta_data($temp)['uri'];$num = md5(time());$headers = "MIME-Version: 1.0\r\n"; // Defining the MIME version $headers .= "From:".$from_email."\r\n"; // Sender Email $headers .= "Reply-To: ".$from_email."\r\n"; // Email addrress to reach back $headers .= "Content-Type: multipart/mixed;\r\n"; // Defining Content-Type $body ="Content-Type: text/calendar; name=invite.ics\r\n"; $body .="Content-Disposition: attachment; filename=\"invite.ics\"\r\n";  $body .= $content; // Attaching the encoded file with email     mail($to_email,$subject,$body,$headers);    fclose($temp);} ?>謝謝
查看完整描述

1 回答

?
牛魔王的故事

TA貢獻1830條經驗 獲得超3個贊

我剛剛做到了,我粘貼了下面的代碼,問題是 php 將新策略應用于新行標題,所以我只需更改一些代碼即可避免此限制并解決問題:


<?php

$temp = tmpfile();


fwrite($temp, $ical);

rewind($temp);

$to_email = '[email protected]';

$subject = 'Testing PHP Mail';

$message = 'Hello';

$from_email = '[email protected]';

$path = stream_get_meta_data($temp)['uri'];


$eol = PHP_EOL;


$filename = "invite.ics";

$mailto = $to_email;

$from_mail = $from_email;

$from_name = "Events";

$replyto = $from_email;


$file = $path;

$file_size = filesize($path);

$handle = fopen($file, "r");

$content = fread($handle, $file_size);

fclose($handle);

$content = chunk_split(base64_encode($content));

$uid = md5(uniqid(time()));

$header = "From: ".$from_name." <".$from_mail.">".$eol;

$header .= "Reply-To: ".$replyto.$eol;

$header .= "MIME-Version: 1.0\r\n";

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"";


$message = "--".$uid.$eol;

$message .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol; // use different content types here

$message .= "Content-Transfer-Encoding: base64".$eol;

$message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol;

$message .= $content.$eol;

$message .= "--".$uid."--";


mail($mailto, $subject, $message, $header);

    

fclose($temp);

?>


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 89 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號