0

Using PHPmailer, has anybody tried to send a tracking pixel, of course with its tracking parameters?

The only working way to send images through PHPmailer is embedded with cid, with code like this:

$mail->AddEmbeddedImage($file_path, $cid_name, $img_name);

Say I have a usual php file that outputs an image while taking track of the open email (writing into a db). If I put a parameter (any kind of) inside the file path or inside the file name, for use with cid, like this:

$token = "984168416987684198jkjkjhfoòiuvutiutciuythfgc";

$file_path_track_img = $imgs_path . "images/track_01.php?tok=" . token;
$cid_track_img = "trackimg";
$img_name_track = "track_01.png?tok=" . token;

echo "<img src='cid:" . $cid_track_img . "'></img>";

and then of course I tell to PHPmailer to use it, like this:

$mail->AddEmbeddedImage($file_path_track_img, $cid_track_img, $img_name_track);

PHPmailer returns error saying it cannot find the file. Doesn't matter if the parameter is written inside path variable or in filename variable, both of those tricks don't work.

I use PHPmailer for a mass amount of work, and "$mail->AddEmbeddedImage($file_path, $cid_name, $img_name)" works always fine.

Anyone has found a solution for sending tracking imgs with PHPmailer?

Synchro
  • 35,538
  • 15
  • 81
  • 104
gab
  • 77
  • 1
  • 1
  • 9

1 Answers1

0

Uh, this can't work!

Embedded images are included with the email message, so nothing happens when the user opens the message – it doesn't need to load an image from you, so it is of no use in tracking the open!

To track an open, just use a regular img tag in the HTML message body that loads the image directly from you, using a unique token for each recipient (or each message):

$mail->Body = 'Hello! <img src="https://www.example.com/images/track_01.php?tok=' . $tok . '" alt="We are spying on you!">';

So long as your track_01.php script returns some kind of image (either a static file or something generated dynamically), it will work fine.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • Uh, I was afraid of that. Of course, in such case, for the beacon image to work, user have to click on "load all images" on most client apps, e.g. Mail on iOS. But that trick seems to be the only way. – gab Jul 08 '20 at 17:39
  • Yes, exactly that. The existence of open trackers is what has caused email clients to add that option! Tracked opens and clicks are increasingly problematic from both a practical implementation point of view and a privacy one. – Synchro Jul 08 '20 at 17:42