asked on
html <img> link to trigger a php script
I have an image in my emails alll ok. But I need to insert an image with a code that as soon as the email is opened it will run a script in my server (php). I know it can be done.
Email trackers insert a code that does that. It is an image that when loaded runs the tracking script.
Email clients that block images are an issue but its ok.
The sending sofware makes the necessary changes so that the correct email is inserted in the message "[email]"
I inserted:
<img src="http://.myphpserver. com/bullet.php?orgx=[email]" width="1" height="1">
bullet.php does the work
Dave is correct, some email (like gmail for example) will most likely block an image that has a querystring. Since you are using the microframework bullet, you do have a way around that.
Instead of
<img src="http://.myphpserver. com/bullet.php?orgx=user@domain.com" width="1" height="1">
You can create a route that looks for the orgx in the path.
http://bulletphp.com/docs/path-callbacks-handlers/.
Try using
<img src="http://.myphpserver. com/newsletter/orgx/user@domain.com/image.jpg" width="1" height="1">
You will create a GET route and your third parameter will be the orgx "user@domain.com". I know that the @ symbol should be legal for windows but I prefer to not use any special characters. Instead, I would opt for the actual user id you have for that person making it
<img src="http://.myphpserver. com/newsletter/orgx/1234/image.jpg" width="1" height="1">
This way you can get one or more parameters to process and it will not get blocked by the email carrier or software.
ASKER
Dave thx
You are right. I dont want all emails set will work with the link. I have a tracker that traks of about 80% em emails and I am ok with that
ASKER
Now. My htaccess take the /newsletter/orgx/1234/image.jpg
If I run it fom the browser it works fine
However when set it as in <img in the email message it does not run the script
<img src="http://myphpserver..com/newsletter/orgx/1234/image.jpg" width="25" height="25">
All images in the email appear find loaded (linked) from myphpserver.com
If I right click to open the image to a new tab it runs the script.
Is the end result to detect if the email is open? or something else?
ASKER
Only detect if the user opened the.email
I agree with Scott. I'm using Sendgrid to send out transactional emails.
I know you selected a different vendor, but the solution is essentially what I suggested earlier in this thread https://www.experts-exchange.com/questions/29248337/html-img-link-to-trigger-a-php-script.html#a43471634
ASKER
Thx
What is your question? Antivirus software will often block links like that. There is nothing you can do that will guarantee that link will work. All of those things are the client's choices.