Google 为图像添加代理 link,图像不显示
Google adds proxy to image link, image doesn't display
我正在从我的组织发送大量电子邮件。我想跟踪谁打开了电子邮件。我知道这不是 100% 可行,但我们仍然会有一些统计数据。
当我通过 Mailchimp 或 Postmark 发送电子邮件时,我可以看到它们正确地跟踪了打开的电子邮件。
图像位于 Amazon S3 上,电子邮件通过 Amazon SES 发送。我用记录用户的 url 设置图像的 src,然后 returns 图像。如果我在浏览器中打开 url,它会正确记录条目并下载图像。
问题是 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;
P.S。我已经在 Stack 和其他网站上阅读了几乎所有关于它的问题。我的代码可能有问题。我不知道。
谢谢你。
这对我有用。感谢 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);
}
}
我正在从我的组织发送大量电子邮件。我想跟踪谁打开了电子邮件。我知道这不是 100% 可行,但我们仍然会有一些统计数据。 当我通过 Mailchimp 或 Postmark 发送电子邮件时,我可以看到它们正确地跟踪了打开的电子邮件。
图像位于 Amazon S3 上,电子邮件通过 Amazon SES 发送。我用记录用户的 url 设置图像的 src,然后 returns 图像。如果我在浏览器中打开 url,它会正确记录条目并下载图像。
问题是 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;
P.S。我已经在 Stack 和其他网站上阅读了几乎所有关于它的问题。我的代码可能有问题。我不知道。 谢谢你。
这对我有用。感谢 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);
}
}