簡體   English   中英

帶有附件的PHP郵件,附件文件為noname

[英]PHP mail with attachment, attachment file is noname

我有以下代碼,可以正確發送帶有正確大小附件的電子郵件,但是附件以“ noname”的形式出現,沒有擴展名。 如果我在下載后手動重命名文件,則無法正常工作。 該文件是mp4視頻。

<?php
$htmlbody = " Your Mail Contant Here.... You can use html tags here...";
$to = "blah@gmail.com"; //Recipient Email Address
$subject = "Test email with attachment"; //Email Subject
$headers = "From: test@mysite.com\r\nReply-To: test@mysite.com";
$random_hash = md5(date('r', time()));
$headers .= "\r\nContent-Type: multipart/mixed; 
boundary=\"PHP-mixed-".$random_hash."\"";
// Set your file path here
$attachment = chunk_split(base64_encode(file_get_contents('test.mp4'))); 


//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative; 
boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; 
charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";


//Insert the html message.
$message .= $htmlbody;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";


//include attachment
$message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: video/vnd.uvvu.mp4
name=\"testing.mp4\"\r\n"."Content-Transfer-Encoding: 
base64\r\n"."Content-Disposition: attachment\r\n\r\n";

$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";


//send the email
$mail = mail( $to, $subject , $message, $headers );

echo $mail ? "Mail sent" : "Mail failed";
?>

只需修改此行,其他所有內容均保持不變:

$filename= "myvideo.mp4";

//include attachment
$message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: video/vnd.uvvu.mp4
name=\"testing.mp4\"\r\n"."Content-Transfer-Encoding: 
base64\r\n"."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";

暫無
暫無

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

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