The concept around this is to serve a 1px image through a PHP script. This allows you to insert a new record or update an existing one about read mails.

In your mail you only have to insert an image tag like this at the end of the template:

<img src="<?php echo url_for('stats/image?bulletin='.$id, 'absolute=true') ?>" alt="px.gif" />

And inside your actions.class.php:

public function executeImage()
{
  if ($bulletin = BulletinPeer::retrieveByPk($this->getRequestParameter('bulletin')))
  {
    // We do database stuff here
  }
  // And serve our image
  $this->redirect('http://'.$_SERVER['SERVER_NAME'].'/images/px.gif');
}

Update:
You can specify a routing rule to match /px.gif?bulletin=id (I don’t remember if you have to modify .htaccess in /web)


3 Comments on “How to count the opening of bulletin e-mail with Symfony”

You can track this conversation through its atom feed.

  1. jzarate says:

    Yeah. But how do you cope with most of the emails programs banning images from the email view panel?

    (And they ban the image for that precise reason).

  2. Carlos Escribano says:

    Well, if I subscribe to an e-mail bulletin I usually want to read the content clearly, so I deactivate the image e-mail load restriction.

    Spam is not my business, you know :P

    I accept other suggestions =)

  3. jzarate says:

    Touché!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>