php mail附件,php-mail()中的电子邮件附件出现问题

我正在尝试通过电子邮件将服务器上的图像作为附件发送.为了完成此任务,我使用了以下PHP脚本,该脚本从我的服务器中捕获位于名为“ screenshots”的目录中的JPG(称为“ php.jpg”),并将其发送为附件.

$path = "screenshots/php.jpg";

$fp = fopen($path, 'r');

do //we loop until there is no data left

{

$data = fread($fp, 8192);

if (strlen($data) == 0) break;

$content .= $data;

} while (true);

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

$mime_boundary = "<<

$headers .= "From: Automatic \r\n";

$headers .= "To: SomeName \r\n";

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

$headers .= "Content-Type: multipart/mixed;\r\n";

$headers .= " boundary=\"".$mime_boundary."\"";

$message .= "This is a multi-part message in MIME format.\r\n";

$message .= "\r\n";

$message .= "--".$mime_boundary."\r\n";

$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";

$message .= "Content-Transfer-Encoding: 7bit\r\n";

$message .= "\r\n";

$message .= "Email content and what not: \r\n";

$message .= "This is the file you asked for! \r\n";

$message .= "--".$mime_boundary."\r\n";

$message .= "Content-Type: image/jpeg;\r\n";

$message .= " name=\"php.jpg\"\r\n";

$message .= "Content-Transfer-Encoding: quoted-printable\r\n";

$message .= "Content-Disposition: attachment;\r\n";

$message .= " filename=\"php.jpg\"\r\n";

$message .= "\r\n";

$message .= $content_encode;

$message .= "\r\n";

$message .= "--".$mime_boundary."\r\n";

$ok = mail("me@gmail.com", "file by email", $message, $headers);

总体而言,该脚本有效.我在收件箱中收到一封电子邮件,其中包含上面指定的消息文本和JPG附件.由于我是新手,所以Stack Overflow不允许我发布照片,但可以在此处获取消息的屏幕截图:http://i48.tinypic.com/xfuee0.png

当我尝试查看附件时出现我的问题.单击附件只是打开一个新的浏览器窗口,并显示一个丢失的图像图标.

您是否看到我的脚本有任何问题,会阻止图像出现?

任何信息都很好.谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值