/phpMailMerge

A PHP mail merge script for sending emails in multipart MIME format

Primary LanguagePHPMIT LicenseMIT

phpMailMerge

A PHP mail merge script for sending personalized emails in multipart MIME format

Sends a serial letter in multipart MIME format to all tagged entries of a CSV database. Depending on the marker two different mail version will be generated, which are previously created as a template. The template is prepared as HTML with placeholders. The sent email also contains an alternative plain text message in addition to the HTML message. If attachments are defined, they will be added.

In short:

  • send mail in HTML and plain text
  • two language versions depending on the database marker
  • include inline images
  • attach files

Background

The script was originally written for conference invitations due a lack of appropriate software solutions. Objectives were full control, use of CSV databases and easy configuration.

Usage

Files

  • phpMailMerge.setup.php: setup script
  • phpMailMerge.send.php: execution script
  • phpMailMerge.database.csv: CSV database
  • phpMailMerge.log.txt: log of the execution script

Requirements

  • PHP 5.4+ server (not tested below)
  • execution rights on phpMailMerge.send.php
  • write access on phpMailMerge.log.txt
  • the database has to be CSV encoded in UTF-8

Workflow

Control your mail merge by setting up all parameters in phpMailMerge.setup.php (file paths, database assignment, sender, subjects etc.). The database has to be in UTF-8 format, otherwise your emails will show cryptic chars. The language column of the database is used for selecting one of the two mail versions. Because the script background lies in a german conference, the selectors are "de" and "en" (also just "d" or "e"). You can use these selectors also for other languages or even two different content versions. The content of your mails are set by HTML files. They include placeholders for the salutation and inline images. Just look at the example HTML files.

The sending process will be started by executing phpMailMerge.send.php (i.e. over the browser address). Make sure you have set all file rights (see requirements).

Placeholders in mail templates

  • %SALUTATION%: Salutation created by the script containing title, first and family name.
  • <img src="cid:imgX">: Inline image. X defines the index in the image list starting with 1. Since it is an HTML tag, it can have corresponding properties.

Tests

The sent emails were tested in Mozilla Thunderbird, Microsoft Outlook and many mobile mail programs.

Disclaimer

Do not use this script for spamming mails. It is intented for professional and amicable use.