Search code examples
serverserver-sidelampemail

How to set up rotating images in email signature


My company has asked me to change our signatures so that the current image we use is replaced by a set of 4 that rotate, so only one shows at a time but they are often changing.

Now the problem is that we use Exclaimer Cloud to manage our signatures for our emails which run through Office 365. Exclaimer have an article on how to achieve it in their software, but for me it looks too time-consuming. I already have about 6 different signature designs for different departments, and their method involves splitting each signature into 3 parts and doing some fancy stuff on it but even they admit that this method requires admin input to reset dates every time the revolving images reach the last one. For me, splitting 6 signatures into 3 parts, setting them all up, managing them ongoing etc is not feasible.

So I've had some other ideas but don't know enough to develop them or know if they would work by myself:

  • I have admin access to a company (LAMP) server. Could I host the images on this and use a script to rename them every X minutes so that a different image matches the link after every time the code runs?
  • Is there any way the server could be set up to deliver a different image every time the link is called?

Exclaimer doesn't support any embedded html in the signature so anything like this has to be server side as far as I can see.


Solution

  • So far as a workaround I've done the following:

    1. I've placed 4 alternate signature design banners in a server directory, then copied one of them and called it banner-main.png
    2. Then I've placed the image in Exclaimer as a signature link to this copied file so [url]/banner-main.png
    3. Then I've created index.php in the same directory with a radio form that allows any of the four images I've uploaded to be selected. When the form is submitted it copies the selected image and renames it as banner-main.png which overwrites the previous file with this name.
    4. I've considered re-writing the code so that the page automatically refreshes every half hour or so, and chooses the next image in the sequence when it does so. It wouldn't be hard to do.

    This method works for me and is relatively simple compared to the Exclaimer way of doing it but is still not ideal. I'd prefer it if the images could be re-written server side without having to open a page in my browser, or some way that doesn't require any human input / maintenance.

    Anyway here is the code I'm currently using, maybe it will help someone else.

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    
    $formval = $_POST["banners"] ;
    $newname = "banner-main.png" ;
    $dir = "/home/armorgar/public_html/sites/productinfo/sig/" ;
    $htmldir = "/sig/" ;
    
    $oldimg = $dir . $formval . ".png" ;
    $newimg =  $dir . $newname ;
    
    
    
    if (copy($oldimg, $newimg)) {
            echo ($formval . " is the new email signature image.") ;
        } else {
            echo "Sorry, there was an error.";
            } ;
    
    
    echo "<br>" ;
    echo '<a href="https://prod.armorgard.co.uk/sig/banner-main.png?var=' . rand(0,100000) . '" target="_blank">Test link to banner</a>' ;
    echo "<br>" ;
    
    ?> 
    
    <h1>Which banner is next?</h1>
    
    <br>
    
          <form action="/sig/index.php" method="post">
             <input type="radio" name="banners" value="banner-1">Banner 1
             <br>
             <input type="radio" name="banners" value="banner-2">Banner 2
             <br>
             <input type="radio" name="banners" value="banner-3">Banner 3
             <br>
             <input type="radio" name="banners" value="banner-4">Banner 4
             <br>
             <input type="submit" value="Submit">
          </form>
    
    </body>
    </html>