Home > php, spam score, swift_mailer > How-to: Lower html email spam score using swift mailer

How-to: Lower html email spam score using swift mailer

Swift mailer is yet another great PHP emailing library. Working as a web developer, I am faced quite often with the tasks of sending out html email. One particular area I always pay attention to is try to lower the emails’ spam score so they won’t end up in recipient’s junk or spam box. Here’s the ‘magic’ code that does the trick:

<?php
        require_once 'lib/swift_required.php'; // or absolute path if swift mailer library is not under current directory
        define('mailhost', 'localhost'); // or external smtp server
        $to='some_recipient@email.address';
        $subject='HTML msg sending test';
        $body='This is a test.';
        $body_html='<p>This is a <strong>test</strong>.</p>';
        $transport=Swift_SmtpTransport::newInstance(mailhost, 25);
        $mailer=Swift_Mailer::newInstance($transport);
        $message=Swift_Message::newInstance($subject)
            ->setFrom( array('noreply@yourcompany.com'=>'Your Company Name') )
            ->setTo( array($to) )
            ->setBody($body)
            ->addPart($body_html, 'text/html');
        $result = $mailer->send($message);

In real-life examples, I’ve seen score dropping by as much as 2.1 by sending html message along with its plain-text counterpart. The reasoning behind this is well explained in this stackoverflow question:
http://stackoverflow.com/questions/5787185/is-it-sensible-to-send-html-only-email-these-days.

Advertisements
Categories: php, spam score, swift_mailer
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: