【问题标题】:Google adds proxy to image link, image doesn't display谷歌为图片链接添加代理,图片不显示
【发布时间】:2016-12-18 00:07:36
【问题描述】:

我正在从我的组织发送大量电子邮件。我想跟踪谁打开了电子邮件。我知道这不是 100% 可行的,但我们仍然会有一些统计数据。 当我通过 Mailchimp 或 Postmark 发送电子邮件时,我可以看到它们正确地跟踪打开的电子邮件。

图像位于 Amazon S3 上,电子邮件通过 Amazon SES 发送。我用记录用户的 url 设置图像的 src,然后返回图像。如果我在浏览器中打开该网址,它会正确记录条目并下载图像。

问题在于 Gmail 在图片前面添加了一个代理,因此根本无法加载图片。 我正在使用 Symfony2.8,这是我发送的响应。

    $response = new Response();

    $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'myimage.png');
    $response->headers->set("Content-Disposition", $disposition);
    $response->setPublic();
    $response->headers->set("Content-Transfer-Encoding", "binary");
    $response->setCache(array('max_age' => 0, 'public' => true));
    $response->mustRevalidate();
    $response->setExpires(0);
    $response->headers->set("Content-Type", "image/png");
    $response->headers->set("Content-Length", 10240);
    $response->setContent(file_get_contents("http://some-amazon-link/assets/logo/pressweb/myimage.png"));

    return $response;

附:我在 Stack 和其他网站上阅读了几乎所有关于它的问题。我的代码可能有问题。我不知道。 谢谢你。

【问题讨论】:

    标签: php image symfony amazon-s3 gmail


    【解决方案1】:

    这对我有用。感谢 Luciano,我在他的网站上找到了解决方案。 http://loige.co/transparent-pixel-response-with-symfony-how-to-track-email-opening/ 跟踪是个人选择,即如何跟踪用户,即使用 id 等。整个代码可以在他的网站上找到。

    class TransparentPixelResponse extends Response  
    {
    /**
     * Base 64 encoded contents for 1px transparent gif and png
     * @var string
     */
    const IMAGE_CONTENT = 
        'R0lGODlhAQABAJAAAP8AAAAAACH5BAUQAAAALAAAAAABAAEAAAICBAEAOw=='
    ;
    
    /**
     * The response content type
     * @var string
     */
    const CONTENT_TYPE = 'image/gif';
    
    /**
     * Constructor
     */
    public function __construct()
    {
        $content = base64_decode(self::IMAGE_CONTENT);
        parent::__construct($content);
        $this->headers->set('Content-Type', self::CONTENT_TYPE);
        $this->setPrivate();
        $this->headers->addCacheControlDirective('no-cache', true);
        $this->headers->addCacheControlDirective('must-revalidate', true);
    }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      相关资源
      最近更新 更多