跟踪电子邮件以真实图像打开 [英] Tracking email opens with a real image
问题描述
我正在考虑将电子邮件跟踪添加到为小型客户业务构建的Web服务中.我打算做嵌入式图像解决方案(参考服务器上的图像)-除非其他人有更好的方法-但是当我使用图像标记引用服务器上的PHP页面时,它将加载已损坏图片"图标.如何使它成为有效的图像?
I'm playing with the idea of adding email tracking to a web service I built for a small client business. I was planning on doing the embedded image solution (with reference to an image on my server) - unless someone else has a better method - but when I use the image tag referencing a PHP page on my server it loads the "broken image" icon. How can I make this a valid image?
这是邮寄PHP页面的代码:
Here is the code for the mailing PHP page:
<?php
$body = "<html>Hello there!".
"<img src='http://mysite.com/track.php?name=bob' />".
"</html>";
$subject = "Tracking on ".date('Y-m-d H:i:s');
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: webmaster@mysite.com' . "\r\n";
mail('my_email@gmail.com',$subject,$body,$headers);
?>
这是跟踪代码:
<?php
include('database_connection.php');
$query = "INSERT INTO tracking SET name='".$_GET['name']."', date=NOW()";
mysql_query($query);
// Tried this, but it doesn't work:
echo "<img src='http://mysite.com/photos/image.jpg'>";
?>
推荐答案
如果要使用这样的PHP脚本,它需要返回图像 data ,而不仅仅是HTML图像标签.最简单的方法是:
If you're going to use a PHP script like that, it needs to return image data, not just a HTML image tag. Easiest way to do that will be something like:
<?php
header("Content-Type: image/jpeg");
readfile("image.jpeg");
do_all_your_tracking_stuff();
请注意,这是首先返回图像数据,以便邮件客户端可以立即开始显示它,而不必等待SQL查询完成.
Note that this is returning the image data first, so that a mail client can start displaying it immediately, rather than waiting for your SQL queries to complete.
这篇关于跟踪电子邮件以真实图像打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!