How to update user table, whenever user viewed email, sent through php? - php

Please check following scenario,
First I am sending email to user using php
Whenever user viewed this email, I want to update my user table.
Is it possible?

Usually you'd put some resource to your email (like an image/tracking pixel) that is loaded from your server. The url of that resource is actually an url to your script. Once the client app tries to load the resources your script gets executed. You get the params you set when sending the email and do what you want with them.
Keep in mind that not all email clients will behave this way. For example plain text email viewers will not load any resources.

Related

How to implement Mailchimp's method for automatically tracking email opens?

Emails containing requested reminders are sent to users daily. My goal is to create a calendar in each marking days in which they opened the email in green. This requires tracking whether the user opens or does not open their email on a given day.
Mailchimp present their method in a blog post
When you send campaigns through MailChimp, we embed a tiny invisible graphic in the bottom of your HTML email... When someone opens your email and views the images within it, that
graphic is downloaded from our server, and it's recorded as an open on
your campaign report.
To break this process down into steps:
1) Including graphic in each email (sent with chron job) unique to user
2) Writing a script that runs whenever the graphic is downloaded from the server and changes an "email_opened" value in a User History table
So my questions:
·How does #1 work? Furthermore, how can I create a system for automatically generating a unique graphic for each user?
My current idea is to send the image from a table using PHP such as:
<? $img_data = file_get_contents("images/phpimage.png"); header("Content-type: image/png"); echo $img_data; ?>
and then somehow set it up to send a different image depending on the email address.
·Where should script #2 be placed and in which language should it be written? My initial thought was php and within the email, but if it's the moment the graphic is downloaded from the server then surely it should be server-side. How would this work?
To "include" an image in an HTML-format email, what you actually have to do is create an <img> tag where the src attribute contains a URL which points back to an image file on your server. (You can't run PHP "within the email", as you contemplated, btw).
For this purpose though, the image could be invisible (using style properties, or by setting height/width to 0), and the src could actually point to a script on your web server which accepts a user ID and email ID as parameters and renders an empty image. The unique URL could be something like http://www.example.com/logEmail?userID=12345&emailID=6789 for a particular user/email combination. The image content that you return from this script is not important and does not need to be unique - remember, it's invisible anyway. Just return a 1px by 1px white square.
When the script runs, before it renders the image back and completes the request, it simply updates your database at the same time with to indicate that the email with the given ID has been read by the user with the given ID.
As for the language, that's entirely up to you depending on how/where you're planning to host the web application. You can achieve what you want in any of the popular server-side languages.
The MailChimp article you linked to makes an important caveat though - this technique won't work if you send any users emails in plain-text for any reason, and nor will it work if the user's mail client is not set to download images (corporate Outlook installs are often set like this by default, for instance, until the user clicks to allow them to be downloaded, and/or marks the sender as safe). So you can't rely on this data as a 100% accurate guide to whether your users are reading your emails or not. If you get a response for a particular email, you can say with certainty that they opened it (N.B. "opening" and "reading" and "understanding" are absolutely not the same thing!!). But if you don't get a response, you cannot in fact be certain whether they opened the email or not.

Is it possible that a url link within an email can be auto-executed by an email client?

We have a script that executes different actions when a user clicks on a specified URL from within the received email. We are getting random records in our database as soon as we send the email to the user. We've checked that we do not have any PHP functions that execute those URLs. So we ask here, is it possible that a URL within an email body can be auto-executed by an email client?
No, that wouldn't be a good thing.

execute script url from a reply to email using PHP

I want to build a system where the user can just reply to the email he gets. What it needs to do is: once the user replies to the email, that email does not go to any user, it will execute a url with GET parameters that triggers a script that updates the database and send another user an email.
Let me explain again:
User A gets into the system to insert his message, his message will send a notification to User B, user B replies to it, but instead of sending to User A, it will Update a database and notify User A saying that User B has sent a message.
the main point is that User A and B does not communicate with each other directly, only allowing them to communicate using the system.
I need to use PHP.
If someone can help or point me into the right direction I will appreciate it!!
Thank you all!!!
If you have access to the system users, you could pipe within the .forward file to a php script.
Or run a php script via cron/wget that logs into that email account and processes emails.
You need a email server, which will be receive and sent messages.
And just read new emails with PHP and do another magic that you want with PHP IMAP functions.

Executing encrypted/secure PHP/SQL script by clicking a link within an e-mail

I'm receiving e-mail from my PHP/MySQL application with certain links.
When I click on a certain link (Approve, for example) within the e-mail, I want a message to be sent back to my Application, which it'd translate into a PHP script or SQL statement to update certain fields in the database.
In order to determine which fields to update, certain user and request related information may be included in the link (user name, category, amount, etc.) but I don't want this to be seen as plain text or discovered by someone looking into the e-mail details (can it be encrypted and then decrypted by the PHP application when user Clicks back in the e-mail)
I want this to happen only if I'm clicking on the original e-mail, not if it it's a forward or reply of the original
NOTE: My Application is not SSL enabled
What components/frameworks could be used to accomplish this and ensuring a perfectly secure solution (i.e. it could be PHP web services, details on what method to use to encrypt/decrypt, etc.)
None. There is no such thing as perfect security. And if you consider that a forward may copy each and every byte of the original, it will be tricky to react differently on links in forwarded messages.
what about letting your user simply reply to the email so your original text is returned. You could be relatively sure, that the user is the only person with access to this particular email- address and you could read your secret and encrypted message from the email-text.
You could let a cronjob run every x seconds, let the php- script read the message for a string like:
<SECRET_INGREDIENT>jkbgv7&%%((Nj3js8<SECRET_INGREDIENT_END>
So php looks for <SECRET_INGREDIENT> and for <SECRET_INGREDIENT_END> and decrypts the part between.

Auto-detect a string in received email via POP3?

I was just wondering some hidden potential in a device I own, and after thinking a while, came up with this:
If an email is sent to "name#domain.com" (this would be specific to the device) from a specific sender, with a part of the body of the message containing a link, can I make a PHP script that accesses said account via POP3, detect emails sent to the address via a specific sender, and then download the file (link) in the email with string "http://www.domain.com/redirect.html?_encoding=" to a directory on my server?
Basically this:
specified sender emails "name#domain.com" with an email that contains a link specified above. PHP script (being called by a web browser) uses POP3 to download the link in the email from the specified sender, saves it to "C:\directory\filename.suffix" automatically?
Even better, is it possible without a PHP script, something that would automatically download the link when the email is received and save it to a directory on the local computer?
Thanks, I'm just trying to find if it is even possible and not waste my time.
Have a look at flourish fMailbox. You can easily access your emails via POP3 with that and check them for your criteria.
One disadvantage if you run the script regularly (e.g. with a cronjob): It's based on the email's 'uid', which probably means 'unique id' - but (at least in my case) it's not so unique at all and changes if you delete emails from the server. So in other words, it's not a unique id but describes the nth email, counting from the first one. So if you don't want to start from the beginning each time you check your mails, you a.) have to store your last 'uid' somewhere and start from there and b.) should not delete emails from the server.
For the rest of your question:
Look if there's a specific link in there: http://de.php.net/manual/en/function.strpos.php
Download the contents: http://de.php.net/manual/en/function.file-get-contents.php
Yes, it's possible. Click this link and scroll-down all the way to the bottom where a user left a comment regarding accessing POP3 folders:
http://php.net/manual/en/book.imap.php

Categories