13/02/2020

The archive contains older posts which may no longer reflect my current views.

# I couldn't sleep last night and spent about half an hour planning an email subscription system for the blog daily feed. I drew a quick diagram and a list to include:

  • register/unregister (add and remove address to/from list in database)
  • send a welcome mail on registering
  • auto-send each day

I made some notes about how I would achieve each element ready for when I woke up before finally dropping off.

# The daily email sign-up is now live on the /Subscribe page and seems to work okay in my (admittedly limited) testing.

Adding and removing your address is fine and the welcome mails go out correctly while redirecting you to a separate welcome page. Removing your address provides a prompt rather than redirecting to a separate page.

Each address in the list is added as a BCC to preserve subscribers privacy. Using wp_mail they are each added as a separate header item so I have to loop through them individually. As an additional privacy measure I might look at encrypting the addresses in the database but that's for another day.

It's a bit rough and ready, and could probably be made a little (okay, a lot) prettier, but it seems to do the trick.

# As with the other automated processes (generating the RSS feeds) the daily email will be triggered by a cron job at 5 past midnight UK time.

# One thing I need to do is move the email generation code to its own template. It's currently on the test page where I try different things before making them live. I don't want to trigger multiple emails each time I forget and go to work on something else.

As with the custom RSS feeds, it's not something I anticipate anyone actually signing up for. I just thought it was worth a shot at creating as much for the intellectual exercise than the functionality.

Maybe, in future, I could hook into it to send additional mails or a newsletter and have it all self-hosted rather than relying on a third party service like Mail Chimp.

1 comment: click to read or leave your own Comments

# The mail generation stuff has now been moved to its own template and the cron job updated so there shouldn't be any accidents.