-1

I want to send a newsletter through email and I would like to see who opened my email.

I send HTML in the content of the email, so I can not add javascript in there. (see here )

Is there any way to send a post request (to my server) only through HTML, every time the HTML is opened and not by pressing a button?

Marileni
  • 3
  • 3

2 Answers2

2

No.

The only HTTP requests that can be triggered by simply opening an HTML document without any JS in it are GET requests.

Tracking of HTML emails is usually achieved using GET requests from images (and usually blocked by email clients because it is intrusive).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

I think you are wanting to track emails which are opened? If you are using a PHP server you can create a simple "pixel" but would need to hook it up to your database.

Inside your email you can load the pixel as an image and replace the %pixel_id%

<img src="https://yoururl/pixel.php?tid=%pixel_id%" style="width:1px;height:1px;"  title="pixel">

Pixel code:

<?php

//YOU NEED TO INCLUDE YOUR DATABASE CONNECTION FILE HERE

    $conn_cms=get_dbc();    
    $stmt = $conn_cms->prepare("SELECT * FROM `pixel_tracker` WHERE `pixel_id` = ?");               
    $stmt->bind_param("s", $tid);
    $tid = $_GET['tid'];
    $stmt->execute();
    $result = $stmt->get_result();
    $assoc = $result->fetch_assoc();// get the mysqli result

    $stmt = $conn_cms->prepare("UPDATE `pixel_tracker` SET `seen` = ?,`seen_count` = ?,
    `seen_when`= ?, `header_track`= ? WHERE `pixel_id` = ?");               
    $stmt->bind_param("sssss", $seen, $seen_count, $seen_when, $header_track, $pixel_id);
    $seen = 1;
    $seen_count = $assoc['seen_count']+1;
    $seen_when = date("Y-m-d H:i:s");
    if(isset($_SERVER['HTTP_REFERER'])){
        $header_track = $_SERVER['HTTP_REFERER'];
    } else {
        $header_track = "none";
    }
    $pixel_id = $tid;
    $stmt->execute();
    $result = $stmt->get_result(); // get the mysqli result

    $pixel = imagecreate(1,1);
    $color = imagecolorallocate($pixel,255,255,255);
    imagesetpixel($pixel,1,1,$color);
    header("content-type:image/jpg");
    imagejpeg($pixel);
    imagedestroy($pixel);

?>

EDIT: If you are sending emails automatically from your server you can dynamically insert the pixel reference in to your database, otherwise for now you can do this manually.

Peter Bennett
  • 184
  • 1
  • 2
  • 15