簡體   English   中英

在PHP中使用MIME的電子郵件文件附件

[英]Email file attachments using MIME in PHP

我正在嘗試使用PHP發送帶有附件的電子郵件。 我已經按照http://webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment上的出色教程進行了以下更改:

--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: application/txt; name="<?php echo $_POST[log_file]?>"  
Content-Transfer-Encoding: base64  
Content-Disposition: attachment 

原始腳本或我的修改腳本似乎都沒有將任何文件附加到我的電子郵件中。 任何人都知道我在做什么錯。

注意:我附加到表單的文件都是文本文件(各種文件擴展名,例如.log,.txt等)。


好的,我現在證明我認為此腳本的MIME編碼部分無法正常工作。 我已經在上載目錄中放置了一個文本文件,並將腳本更改為:

--PHP-mixed-<?php echo $random_hash; ?>   
Content-Type: text/plain; name="<?php echo $_SERVER['DOCUMENT_ROOT']. '/upload/test.txt' ?>" 
Content-Transfer-Encoding: base64  
Content-Disposition: attachment 

當查看收據上的電子郵件來源時,我在Content-Type下看到完整的路徑和文檔名稱:text / plain; name =,但沒有附件,無論編碼還是其他形式。

有人知道我該如何工作嗎?

我嘗試了以下方法:

--PHP-mixed-<?php echo $random_hash; ?>   
Content-Type: text/plain; name="<?php echo $_FILES['file']['name']; ?>"
Content-Transfer-Encoding: base64  
Content-Disposition: attachment

有趣的是,這顯示了電子郵件源中的文件名,但沒有附件:

--PHP-mixed-<?php echo $random_hash; ?>   
Content-Type: text/plain; name="<?php echo $_FILES['file']['temp_name']; ?>"
Content-Transfer-Encoding: base64  
Content-Disposition: attachment 

返回一個空文件名並且仍然沒有附件,我只能假定在執行此操作時臨時文件已被刪除?

確定最終通過將臨時文件移動到服務器上的另一個位置,然后對該文件進行編碼來使此工作正常。

不知道為什么不保存就不能對臨時文件進行編碼,但是至少我現在能使它工作。

感謝所有花時間回答此問題的人,您對我有很大幫助。

暫無
暫無

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

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