douanrang4728 2016-08-11 10:02
浏览 92
已采纳

Google为图片链接添加了代理,图片无法显示

I am sending bulk emails from my organisation. I want to track who has opened the email. I know it's not 100% feasible but still we'll have some stats. When I send emails through Mailchimp or Postmark, I can see they correctly track the opened emails.

The image is located on Amazon S3 and the emails are sent through Amazon SES. I set the src of the image with our url which records the user and then returns the image. If I open that url in browser, it correctly logs the entry and downloads the image.

The problem is that Gmail adds a proxy in front of the image thus the image doesn't load at all. I am using Symfony2.8 and this is the response which I send.

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

P.S. I have read almost all the questions about it on Stack and other websites. There may be something wrong with my code. I dunno. Thank you.

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-08-16 12:56
    关注

    This is what worked for me. Thanks to Luciano, I found the solution on his site. http://loige.co/transparent-pixel-response-with-symfony-how-to-track-email-opening/ The tracking is a personal choice, how you track your users i.e. using id etc. The whole code can be found on his site.

    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);
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号