Aiden Stewart Aiden Stewart - 1 year ago 77
PHP Question

PHP mailsender: Which receivers are clicking on my [Html message] link?

I'm using a PHP mailsender and sending a link to a number of receivers. When they click on the link they will redirect to a PHP file that get their ip and then a header on that PHP file that redirect to a webpage.

This is my Question: Which ip is for which email (or reciever) ??

This is the link code im sending to :

<a href="" style="(css part)" >blahblah</a>

And this is the php code that get the recievers ip and writing to a txt file :

$data = ' ip --> '.$_SERVER['REMOTE_ADDR']."\n" ;
$ret = file_put_contents('data.txt', $data, FILE_APPEND | LOCK_EX);

If my question isnt clear please tell me to describe more.THANKS

Answer Source

If I understand your question correctly, what you are actually trying to accomplish is to figure out which person has opened your email, and you are collecting the IP address as a proxy, and then hope to figure out who it was based on the IP address.

Unfortunately, that is not going to work. Many (most) companies use NAT based firewalls, and thousands of users could all be accessing the Internet through the same IP address. And conversely, the same user can have a different IP address in the morning when he stops at Starbucks, in the afternoon at his desk at work, and after he gets home.

If you add IPv6 to the mix, things get even more complicated.

To solve your problem, you need to take a different approach. One easy solution is to assign each recipient a random, but unique, code. A 32-character string of hexadecimal digits would be good.

When you send the email, you store this code and the email address it belongs to. The link in your email would look like this:

<a href="" style="(css part)" >blahblah</a>

Note that this means that the URL will be different for each email you are sending.

On the receiving end, your data.php would then extract the code from the URL and save it to your database.

All that said: you will likely not be very happy with such a homegrown solution. You can buy software that does it off the shelf (or as a service), with very elaborate reporting capabilities.

Your biggest challenge will likely be spam filters and privacy filters - both can look for exactly that kind of code in a URL. With a commercial off-the-shelf solution, you leave this type of issue to the experts.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download