I’m using PHP to generate an html email which sends my clients latest stats in graph form. PHP generates a new image everytime it sends out stats with the same image name to prevent high disk space usage. Now my problem is the image gets cached thus displaying the old image to the client instead of the new image.
My html headers look as follows.
"From: Test <test@test.com>\n"
// . "To: " . $contact . " <" . $email . ">\n"
. "To: myemail@test.com\n"
. "X-Confirm-Reading-To: test@test.com\n"
. "Disposition-Notification-To: test@test.com\n"
. "MIME-Version: 1.0\n"
. "Content-Type: multipart/mixed;"
. ' boundary="PAA08673.1018277622/www.test.com"'
. "\nSubject: Stats for $name\n\n"
. "This is a MIME-encapsulated message\n\n"
. "--PAA08673.1018277622/test@test.com"
. "\nContent-Type: text/html\n\n";
How can I force the mail to download the latest generated image from the server?
Include something extra in the URL, like the timestamp of the graph image
That way, the URL changes whenever the image does. This won’t stop the user-agent from caching what it sees, so it still might show an old image even after the server updates.
So, if you want to stop the user-agent from actually caching the image, then write a script which returns the image with some headers to prevent caching….