inicio sindicaci;ón

Tips for creating a small but solid newsletter-system

I guess many developers could have the same challenge: Their customers want to send out a newsletter, but they don’t need an enterprise newsletter system because they send only to about 100 - 5.000 recipients. Futhermore, they wanna send it through their normal CMS application.

Here are some tips about writing a solid solution for sending a newsletter, which fit into the most requirements:

//Use a Framwork
Use a completed Framework to create and send mails, not the PHP mail function. For example: PEAR::Mail, eZ Components, Zend Framework.

You don’t have to care about encodings, escaping etc. then. This is also a security aspect as it could be possible that some evil person injects something into your headers!

//Queue in the database
Create a queue table in your database. Put every single mail with full headers and full text in a row. I know this produces redundant data, but with this you have a complete logging and solid queue solution without big trouble. Here is our SQL:

CREATE TABLE `newsletter_queue` (
`newsletterID` bigint(20) NOT NULL auto_increment,
`create_time` datetime NOT NULL default '0000-00-00 00:00:00',
`time_to_send` datetime NOT NULL default '0000-00-00 00:00:00',
`sent_time` datetime default NULL,
`newsletterreceipientID` bigint(20) NOT NULL default '0',
`newsletterjobID` int(11) default NULL,
`sender` varchar(100) NOT NULL default '',
`recipient` varchar(100) NOT NULL default '',
`headers` text NOT NULL,
`body_txt` mediumtext NOT NULL,
`body_html` mediumtext,
`try_sent` tinyint(4) NOT NULL default '0',
PRIMARY KEY  (`newsletteID`),
KEY `newsletterjobID` (`newsletterjobID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

So you have a complete queue, you can interrupt and delete the queue if something goes wrong. Let some background daemon execute the jobs.
For archiving, use something like the MySQL MERGE storage engine.

//Use SMTP
It is a good idea to use the same SMTP server that the customer uses to send out his normal emails, especially when you set SPF Records. Look at your Return-Path and From: headers so that they match the sender domain.
//Check Headers
From time to time I notice that the headers are not complete. So make sure that the Date: and the To: field are in the appropriate format (in PHP: date(r);).

// Test it
Make a test with several MUAs and anti-spam solutions like the popular SpamAssassin and check if they complain about some wrong headers and /or keywords.

We hope these hints are useful for you. Comments, additions and corrections are always appreciated.

Ein Kommentar to “Tips for creating a small but solid newsletter-system”

  1. MarkusWolff Says:

    Other mail classes of interest:
    http://phpmailer.sourceforge.net/
    …or it’s inofficial successor:
    http://www.swiftmailer.org/

    I’ve used PHPMailer in the past and it has proven to be very reliable, offers good debugging capabilities and is very easy to use.

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image