How To Build A Bulk Email Sending Application In PHP
-
Upload
sudheer-satyanarayana -
Category
Technology
-
view
49.717 -
download
2
Transcript of How To Build A Bulk Email Sending Application In PHP
PowerPoint Presentation
Sending Bulk Email Using PHP
BySudheer Satyanarayanahttp://techchorus.net
Table Of Contents
Bulk email challenges
Tools and techniques
Best practices
Sample code
Question and answers
Challenges
User's expectations
Outgoing emails restrictions set by hosting providers
Incoming email filters set by recipient servers and their users
Compliance - legal and tacit agreements
Avoiding getting blacklisted
Prerequisites
Opt-in list
Own email server for full blown solution
Servers are becoming less expensive
Amazon - $0.085 per hour / INR 3.99 per hour
Rackspace Cloud - 1.5 per hour / INR 0.7 per hour
Identity And Branding
Use dedicated public static IP address
Have correct reverse DNS record for your IP address
Have up to date contact information in WHOIS record
Monitor postmaster and abuse mailboxes
Have a consistent from header
Have SPF records
Sign messages using DKIM
Identity And Branding - Reverse DNS
Forward DNS lookup maps domain name to an IP address
Reverse DNS lookup maps IP address to a domain
Server hosting providers offer a way to set the reverse DNS entry in their control panels
Example
31.41.51.61 pointing to myserver.example.com
Headers
Email contains two major sections
HeaderHeader sections fieldsExample fields - From, To, Subject, Date, Message-Id
BodyUnstructured
Sample Email With Headers
Use A PHP Library
Prefer SMTP over sendmailPopular PHP libraries that support SMTP
Zend Framework - Zend_Mail
PHPMailer
Swift Mailer
Zend_Mail Sample Usage
Configure SMTP Before You Send.Use this snippet if SMTP authentication is not required
$config = array('name' => 'myserver.example.com');$transport = new Zend_Mail_Transport_Smtp('myserver.example.com', $config);
Zend_Mail_Transport_Smtp('myserver.server.com', $config); Zend_Mail::setDefaultTransport($transport);
Zend_Mail Sample Usage
Use this snippet if SMTP authentication is required
$config = array( 'auth' => 'login', 'username' => 'myusername', 'password' => 'password');$transport = new Zend_Mail_Transport_Smtp('myserver.server.com', $config); Zend_Mail::setDefaultTransport($transport);
Zend_Mail Sample Usage
$mail = new Zend_Mail();$mail->setBodyText('Hello World!');$mail->setFrom('[email protected]', 'You');$mail->addTo('[email protected]', 'Me');$mail->setSubject('Greetings');$mail->send();
From, To, Subject headers are automatically set by Zend_Mail.
Zend_Mail also handles MIME encoding.
Identity And Branding - SPF Record
Sender Policy Framework
Email Validation System
Have a text DNS record and publish your policy
Recipient servers validate sender by reading your DNS record
SPF Example:"v=spf1 ip4:192.168.0.1/16 -all"Allow any IP address between 192.168.0.1 and 192.168.255.255.Use the SPF record generatorhttp://old.openspf.org/wizard.html
Identity And Branding - DKIM
DomainKeys Identified Mail
A method for email authentication
Public key cryptography
Example HeaderDKIM-Signature: d=example.com s=myserver b=MTI...I=;
List Management - Subscribing
Let users explicitly opt in to your lists
Verify the subscriber's email address
Consider double opt in
Avoid purchasing lists
Send subscription reminders to users. Offer methods to unsubscirbe from the lists the user may no longer be interested in.
List Management - Unsubscribing
A link in every email. Do not ask the user to login to unsibscribe
Do not force the user to fill in 'reason' field in the unsubscribe form field. Use unsubscribe form only for confirmation.
Provide a 'List-Unsubscribe' header
Automatically unsubscribe users whose addresses have reached a bounce threshold. Use VERP.
List Management - Unsubscribing
List-Unsubscribe Header
$mail = new Zend_Mail();$mail->setBodyText('Hello World!');$mail->setFrom('[email protected]', 'You');$mail->addTo('[email protected]', 'Me');$mail->setSubject('Greetings'); $mail->addHeader('List-Unsubscribe', '[email protected]');$mail->send();
List Management - Unsubscribing
List-Unsubscribe Header With Unique Identifier
$mail->addHeader('List-Unsubscribe', '[email protected]');
List Management - Unsubscribing
Return-Path Header
Return-Path header's value is usually same as From
Depends on your email server setting
When an email is bounced the details are sent to the email address specified in the Return-Path header
Return-Path: [email protected]: [email protected]
List Management - Unsubscribing
VERP - Variable envelope return path
Automatic Bounce Handling
Make use of Return-Path header
Return-Path: [email protected]
Server must support VERP
List Management - Unsubscribing
Without VERPReturn-Path: [email protected] VERP
Return-Path: [email protected]
Use POP to fetch mails of [email protected] and parse the Return-Path header.
List Management - Unsubscribing
Automatic Bounce Handling - VERP
Fetching mail using POP$mail = new Zend_Mail_Storage_Pop3(array( 'host' => 'localhost', 'user' => 'test', 'password' => 'test'));foreach ($mail as $messageNumber=>$message) {$headers = $message->getHeaders();$to = $headers['to'];//... }
Delivering To Inbox
Ask the user to add your email address set in the from header to their address books
If falsely flagged as SPAM, ask the users to flag the email as not SPAM
Use separate from email address for transactional emails and promotional emails
Use separate IP address for transactional emails and promotional emails
Use separate domains for transactional emails and promotional emails
Settings To Administer The Program
Number of outgoing emails per hour
Number of outgoing emails per hour per domain
List of blacklisted domains
Delay between outgoing emails
Process bounce handling every __ hours
Bounce treshold
Tips And Tricks
Log every action
Respond to user's complaints
Apply for whitelists when you have a problem
Sample entitiessubscriber - email, preferred format, namelist - namelist_subscriber - lookup table. One subscriber can belong to many lists.message - subject, text body, HTML bodymessage_queue - subscriber_id, message_id, list_id, sent, sent_time, unique_identifier
Thank You
Contact - [email protected]://techchorus.nethttp://projects.binaryvibes.co.in/projects/show/barehttp://projects.binaryvibes.co.in/projects/show/bizsensehttp://binaryvibes.co.in
Licence
Sending Bulk Email Using PHP by Sudheer Satyanarayana is
licensed under a Creative Commons
Attribution-NonCommercial-NoDerivs 2.5 India License.
Based on a work at techchorus.net.
Permissions beyond the scope of this license may be available at
http://techchorus.net.