Oct 7, 2014

The organization I work for has always had a nagging problem with their email newsletters: The anchor links forming the table of contents did not actually move the user to their desired story in Gmail. For one newsletter with a comparatively small audience this wasn’t a world-ending issue–almost everyone who opened it was cursed with Outlook, which counter-intuitively did what it was intended to. On the other hand, the remaining large newsletter reached over 8000 subscribers who, with rare exception, all used Gmail.

The difficulty in the matter came from using MailChimp in the particular way we were–and still are–attempting to, which is unusual given its extreme ease of use. The newsletters were constructed using FEEDBLOCK merge tags which pulled news and announcements from several WordPress blogs relevant to the audience. Since multiple blogs were on the page, the table of contents for each needed to be built manually with its own FEEDBLOCK merge tag. Trick was, how could you create an anchor link from one feed block to the other using the information that the merge tags are capable of pulling from the feed?

Using the title wasn’t an option. Its spaces and special characters ensured it would be handled differently client-by-client, and we had already seen this wouldn’t work in Gmail. The same went for the URL; its characters were not within the valid range to use as names/IDs for elements. We searched a great deal to see if MailChimp could output an iterator for each FEEDITEM in a FEEDBLOCK merge tag, but to no avail, so “#events4” was out of the question. What we needed was a valid UID for each post that could be generated both in the TOC FEEDBLOCK and the content FEEDBLOCK merge tag.

Our breakthrough came when we realized the FEEDITEM:DATE merge tag could take further customization and be formatted in a manner that we chose, including just as a string of numbers. By using the merge tag *|FEEDBLOCK:DATE:mdyHis|*  we could output an almost assuredly unique string of numbers based on the month, day, year, hour, minute, and second a post was published. By prepending a word to this number, we got a unique, valid name that could be used for anchors, such as “anchor091914141227.” An element, then, would look as follows:

<a href="*|FEEDITEM:URL|*" name="anchor*|FEEDITEM:DATE:mdyHis|*">
	*|FEEDITEM:TITLE|*
</a>

This strategy functioned in both Outlook and Gmail.

For additional information about how the FEEDITEM:DATE merge tag can be customized, see the available formats in the PHP manual at http://us3.php.net/manual/en/function.date.php

Fork me on GitHub