Rating by Email Software
To implement a rating feature for your outgoing email, two things are needed.
- The rating software.
- Links in the email.
When implemented, your email will have character links something like this:
Before putting the rating links into your email, the rating software needs to be installed on your server. It is a PHP script.
Here is the source code. Notes follow.
<?php /* Email Rate Log Version 1.1 October 20, 2023 Will Bontrager Software LLC https://www.willmaster.com/ */ /* Two places to customize (article has instructions). */ // (1) The location of the CSV log file. $LogFile = __DIR__.'/EmailVoteLog.csv'; // (2) The content to show after rating. $ContentToDisplay = <<<CONTENT <div style="display:table; margin:.25in auto;"> <p>Thank you!</p> <p>Your feedback is appreciated.</p> </div> CONTENT; /* Customization complete. */ $LogLine = array(); $LogLine[] = str_replace('"','""',date('r')); $LogLine[] = $_SERVER['REMOTE_ADDR']; $LogLine[] = rawurldecode($_SERVER['QUERY_STRING']); file_put_contents($LogFile,'"'.implode('","',$LogLine)."\"\n",FILE_APPEND); echo $ContentToDisplay; exit; ?>
Notes:
Copy the source code and save the file as emailvote.php
(or other *.php
file name that you prefer). The following customizations may be changed before installing the software.
-
The
__DIR__.'/EmailVoteLog.csv'
value tellsemailvote.php
that the CSV file is in the same directory asemailvote.php
and thatEmailVoteLog.csv
is the name of the CSV file.If you want the CSV to have a different file name or be stored in a different location, change
__DIR__.'/EmailVoteLog.csv'
accordingly. -
The
red
text is the content and HTML markup to publish when someone taps your rating link. You'll see it in the source code between the lines that have the wordCONTENT
within them.If you make no changes, the script will output something like this:
Thank you!
Your feedback is appreciated.If you want to publish a different message, change the
red
text accordingly.
When the customizations are done, upload emailvote.php
to your server. Make a note of the script's URL. You will use the URL in the links to be published in your email.
With emailvote.php
installed and its URL at hand, let's put the voting links into an email.
Here is the source code.
<div style="display:inline-block; margin-right:2em;"> <a href="https://example.com/emailvote.php?vote=yes&issue=1265"><span style="font-size:50px; color:#090;">✔</span></a> </div> <div style="display:inline-block;"> <a href="https://example.com/emailvote.php?vote=no&issue=1265"><span style="font-size:50px; color:#f00;">✖</span></a> </div>
Paste the above into your email and then replace both instances of https://example.com/emailvote.php
with the URL of your newly uploaded emailvote.php
script.
Also change or remove the &issue=1265, if you wish. You may also add other URL parameters, anything you want to keep track of.
The CSS may be changed as needed.
When a voting link is clicked, the CSV file logs the time, the IP address, and whatever parameters the voting link had at the time it was clicked.
Because the IP address is logged, it is relatively easy to remove duplicate votes.
Put the voting links in every email that you want votes for.
(This content first appeared in Possibilities newsletter.)
Will Bontrager