【问题标题】:Image not visible in email when inserting with <img> tag but visible when using direct link使用 <img> 标签插入时图像在电子邮件中不可见,但使用直接链接时可见
【发布时间】:2014-08-03 00:18:15
【问题描述】:

我有一个创建图像的非常基本的脚本。让我们假设它在服务器 example.com 上并命名为 test.php

$im=imagecreate(150,150);
$white=imagecolorallocate($im,0,0,0);
imagesetpixel($im,1,1,$white);
header("content-type:image/jpg");
imagejpeg($im);
imagedestroy($im);

当我现在拨打http://example.com/test.php 时,我可以看到一张图片。但是当我想发送电子邮件并将其设置为正文时

<img border='0' src='http://example.com/test.php' width='150' height='150'>

但是,现在我没有看到图像。我只看到一个空白方块,没有源图片网址。我正在使用 GMail,但它在 Apple Mail 中也不起作用。邮件也不会进入垃圾邮件文件夹,因此不会阻止图像。也没有 .htaccess 阻止访问或类似的东西。

还有什么想法吗?

【问题讨论】:

  • 必须尝试在 html 页面中使用它以查看它是否有效?如果它只是在电子邮件中,它可能是一个安全问题。

标签: php html image .htaccess email


【解决方案1】:

标题中有问题,它们区分大小写。内容类型与内容类型不同。并且 mime 类型 image/jpg 不存在,您应该使用 image/jpeg。

$im=imagecreate(150,150);
$white=imagecolorallocate($im,0,0,0);
imagesetpixel($im,1,1,$white);
header("Content-Type: image/jpeg");
imagejpeg($im);
imagedestroy($im);

这应该可行。

【讨论】:

    猜你喜欢
    • 2015-08-26
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2016-07-27
    • 2014-08-06
    相关资源
    最近更新 更多