douxun7992 2013-07-23 15:27
浏览 63

使用PHP中的MIME发送电子邮件文件附件

I'm trying to use PHP to send an email with an attached file. I've followed the excellent tutorial at http://webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment and made the following changes:

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

Neither the original script or my amended script seems to attach any files to my emails. Anyone have any idea what I'm doing wrong.

Note: the files I'm attaching to my form are all text files (various file extensions e.g. .log, .txt etc).


OK, I've now proven I think that the MIME encoding part of this script isnt working. I've placed a text file in my upload directory and changed the script to read:

--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 

When looking at the email source on receipt I see the full path and document name under Content-Type: text/plain; name=, but theres no attachment, encoded or otherwise.

Anyone know how I get this to work?

I've tried the following:

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

This presents the file name in the email source, but no attachment, interestingly:

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

Returns an empty file name and still not attachement, I can only assume the temp file has bee deleted by the time I execute this?

  • 写回答

1条回答 默认 最新

  • douchibu7040 2013-07-25 10:19
    关注

    OK finally got this working by moving the temp file to another location on my server, then encoding that file.

    Not sure why I can't encode the temp file without saving it, but at least I got it working now.

    Thanks to everyone who took the time to reply to this, you help me a lot.

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码