Skip to content

A mail merge client with click-tracking and a high level of flexibility. Webversions are generated automatically from your template. Well-commented code is easy to alter.

Notifications You must be signed in to change notification settings

davegregg/PHP-Mail-Merge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Mail Merge

PHP Mail Merge distributes variable email campaigns. If you need to send a single basic email to a large number of recipients, but you want each email to be slightly different (e.g. for branding purposes, or to include the recipient's name or a unique promotional code), then PHP Mail Merge can help you.

This was my first PHP project, churned out quickly over a long weekend to fill a particular company requirement, and I haven't taken the chance to go back over it. For a few thousand emails, I can tell you it worked reliably and reproducibly for several months.

  1. Supply PHP Mail Merge with a template, containing unique variables in the places you need the varying content to go.
  2. Supply a comma-delimited list of these variables, so PHP Mail Merge knows what to look for in your template.
  3. Supply the list of recipient addresses, and the associated recipient-unique values to replace the variables in your template.

PHP Mail Merge will parse through the template looking for each variable, replacing it with the value you supplied, and then send the final email to the address you supplied. Webversions of each email are generated for the recipient to view in their browser (if desired) and click-tracking functionality is built-in.

Tips

  • Variables can be used not only in the body of the email, but in the subject line, sender's address, and reply-to address, which are especially handy for dynamic branding
  • There are a few hardcoded variables you should know:
    • ___dmgmmURL returns the URL of the webversion of the email (obviously, for providing a 'view-in-your-browser' copy of the email to recipients)
    • ___dmgmmTrackThis_ (note the trailing underscore) when prefixed to a URL in an anchor link, the link will redirect the user through the PHP of the webversion file which will track the click in the view log and then forward the user on to the destination URL
    • ___dmgmmRecipient returns the recipient's email address (in case you want to repeat a recipient's email address to them
    • ___dmgmmSender returns the sender's email address (handy for dynamic email signatures and the like)
    • ___dmgmmReplyTo returns the reply-to email address (handy for unsubscribe mailto links and the like)
    • ___dmgmmSubject returns the reply-to email address (handy for the HTML title tag in the webversion, for example)

TODOs

  • Security review (e.g. sanitization)
  • Refactoring: This was written ~2010. I didn't observe a popular styleguide. And PHP itself has changed quite a bit since then, both with the advent of PHP 5 and with developed conventions. So this code should be revised for new patterns and practices.
  • Optimization for scaling: the app works fine for a few thousand emails at a time. I've not had an occasion to test this with larger jobs.
  • UI/UX update: it's certainly not pretty. It was a quick solution for a technician.
  • More documentation (e.g. for records and logs)
  • Replace ___dmgmmFoo template variables with the common convention of %foo% or {{foo}}
  • Use Heredocs insteads of sequences of appended strings
  • Add a logging option
  • Add memory-limit-error mitigation, by providing an option for the user to give a list of files containing address-values sets, instead of a list of sets directly into the form
  • Strip whitespace and newlines from between address-values sets intelligently
  • Add option to pull the template from a file
  • More error handling

About

A mail merge client with click-tracking and a high level of flexibility. Webversions are generated automatically from your template. Well-commented code is easy to alter.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published