SlideShare a Scribd company logo
Sending E-mail that reaches
      the destination

             Manuel Lemos
             mlemos@acm.org

       http://www.ManuelLemos.net/

  http://www.phpclasses.org/mimemessage
The problems
    Sending e-mail is fundamental
●



    PHP native support for sending e-mail is
●

    deficient
    The Internet e-mail standards are complicated
●



    Incorrectly composed messages are
●

    discarded
    Correctly composed messages are confused
●

    with SPAM
Solution
    Ready to use PHP components for sending
                      e‑mail
    PHPMailer
●



    PEAR Mail
●



    SWIFT mailer
●



    MIME message
●



    Etc.
●
What is MIME?
    Multipurpose Internet Mail Extensions
●




    Standards for sending E-mail messages
●




    Defined by many RFC documents: Request
●

    For Comments

    New RFC document versions are compatible
●

    with past versions
MIME message class

      PHP class to compose and send e-mail
    Sends messages with text and HTML using
●

    any character set
    Embeds related files: images, CSS, etc..
●



    May attach multiple files
●



    Optimized for sending newsletters to many
●

    recipients
Text message
require('email_message.php');
$m = new email_message_class;
$m->SetEncodedHeader('Subject', 'This is the subject');
$m->SetEmailEncodedHeader('From', 'john@here.com', 'John');
$m->SetEmailEncodedHeader('To', 'joe@there.com', 'Joe');
$text = “Hello Joe,nnThis is the message.”;
$m->AddQuotedPrintableTextPart($text);
$m->Send();
HTML message
$html =
  “<html><head><title>Messagm</title></head><body>Hello
  Joe,<br />n<br />nThis is the message.</body></html>”;
$text = strip_tags($html);
$m->CreateQuotedPrintableHTMLPart($html, '', $h);
$m->CreateQuotedPrintableTextPart($text, '', $t);
$alternatives = array($t, $h);
$m->AddAlternativeMultipart($alternatives);
$m->Send()
HTML messages with
            embedded images
$image=array(                        $m->CreateQuotedPrintableHTMLPart
                                    ($html, '', $h);
 'FileName'=>'image.gif',
 'Content-Type' =>                  $text = strip_tags($html);
   'automatic/name',
                                     $m->CreateQuotedPrintableTextPart
 'Disposition'=>'inline'            ($text, '', $t);
);
                                    $alternatives = array($t, $h);
$e->CreateFilePart($image, $i);      $m->AddAlternativeMultipart
                                    ($alternatives);
$url = 'cid:'.                       $related = array(
                                      $alternatives,
$m->GetPartContentID($i);
                                      $i,
 $html = quot;<html>                     );
<head><title>Message</title>
                                     $m->AddRelatedMultipart
</head><body><img src=”$url” />
                                    ($related);
Hello Joe,<br />n<br />nThis is
the message.</body></html>quot;;        $m->Send()
Message with attached files
$attachment=array(
 'Data'=>'This is an attachment called attachment.txt',
 'Name'=>'attachment.txt',
 'Content-Type'=>'automatic/name',
 'Disposition'=>'attachment',
);
$m->AddFilePart($attachment);
$attachment=array(
 'FileName'=>'attachment.zip',
 'Content-Type'=>'automatic/name',
 'Disposition'=>'attachment',
);
$m->AddFilePart($attachment);
$m->Send();
Sending via SMTP
 Supports several types of authentication using
   the SASL classes: LOGIN, MD5, NTLM, etc.
require('sasl.php'); require('smtp.php');
require('smtp_message.php');
$m = new smtp_message_class;
$m->smtp_host = 'smtp.gmail.com';
$m->smtp_port = 465;
$m->smtp_ssl = 1;
$m->smtp_user = 'some_user';
$m->smtp_password = 'some_password';
$m->direct_delivery = 0;
Sending via sendmail, qmail
   and Microsoft Exchange
          Faster delivery to the MTA queue
require('sendmail_message.php');
$m = new sendmail_message_class;
$m->delivery_mode = SENDMAIL_DELIVERY_DEFERRED;

require('qmail_message.php');
$m = new qmail_message_class;

require('pickup_message.php');
$m = new pickup_message_class;
Mail() function alternatives
    When the mail() function does not work well

    smtp_mail()
●




    sendmail_mail()
●




    qmail_mail()
●




    urgent_mail()
●
The path of the messages

       Local SMTP            Local queue   Destination queue

SMTP                Pickup

       PHP script               MTA        Destination SMTP
                       mail()
                             Direct
The best delivery methods

1.Drop a message file in the local queue

2.Pass to MTA with the mail function (sendmail)

3.Pass to the local SMTP server

4.Direct delivery to the destination SMTP server
Optimizing the delivery of
    non‑personalized newsletters
$list = array(
 'peter@here.com'=>'Peter',
 'paul@there.com'=>'Paulo',
 'mary@overthere.com'=>'Mary'
);
$m->SetBulkMail(1);
$m->cache_body = 1;
foreach($list as $email => $name) {
 $m->SetEncodedEmailHeader('To', $email, $name);
 $m->Send();
}
$m->SetBulkMail(0);
Optimizing the delivery of
     personalized newsletters
$m->SetBulkMail(1);
$m->cache_body = 0;
$template = 'Hello {name}, ...';
$m->CreateQuotedPrintableTextPart($template, '', $part_template);
$m->AddPart($part_template);
foreach($list as $email => $name) {
  $m->SetEncodedEmailHeader('To', $email, $name);
  $text = str_replace('{name}', $name, $template);
  $m->CreateQuotedPrintableTextPart($text, '', $personalized);
  $m->ReplacePart($part_template, $personalized);
  $m->Send();
}
$m->SetBulkMail(0);
Handling returned messages
1.Set the Return-Path message header to an
  address associated with a POP3 mailbox
2.Periodically poll that mailbox using a
  POP3 client class
3.Process the returned messages with the
  MIME parser class
4.Unsubscribe from the newsletters the e‑mail
  addresses that are returning the messages
Know when a message was
          received
         Techniques that do not always work

1.Set the Disposition-Notification-To
  message header to an address to which
  reception notices will be sent

2.Insert a beacon image in an HTML message
  using the URL of a script that accounts
  messages that are viewed by recipients
<img src=”http://www.meusite.com.br/conta.php?usuario=joao@ali.com.br”>
Avoid confusion with SPAM
 What types of messages you should not send?
● Sent from an IP address without reverse DNS

  record (PTR) or that is listed in blacklists
● The recipient e-mail addresses are in Bcc


    Only with an HTML part or has invalid HTML
●


    With beacon image URL that has parameters
●


    Link URLs do not match anchor text URL
●


    Do not pass SpamAssassin checks
●
Questions?


        Manuel Lemos
       mlemos@acm.org

http://www.phpclasses.org/mimemessage
References
    MIME Message class
●


    http://www.phpclasses.org/mimemessage
    SMTP client class
●


    http://www.phpclasses.org/smtpclass
    SASL authentication class
●


    http://www.phpclasses.org/sasl
    POP3 client class
●


    http://www.phpclasses.org/pop3class
    MIME parser class
●


    http://www.phpclasses.org/mimeparser
    Verify IP addresses in multiple blacklists
●


    http://openrbl.org/
    SpamAssassin
●


    http://spamassassin.apache.org/

More Related Content

What's hot

Finding a Better Way to CSS: Navigating Sass with Compass
Finding a Better Way to CSS: Navigating Sass with CompassFinding a Better Way to CSS: Navigating Sass with Compass
Finding a Better Way to CSS: Navigating Sass with Compass
Claudina Sarahe
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
Daisuke Komatsu
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
husnara mohammad
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
Html Cheat Sheet
Html Cheat SheetHtml Cheat Sheet
Html Cheat Sheet
brighteyes
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using php
Rishabh Srivastava
 
php $_GET / $_POST / $_SESSION
php  $_GET / $_POST / $_SESSIONphp  $_GET / $_POST / $_SESSION
php $_GET / $_POST / $_SESSION
tumetr1
 
Sass
SassSass
Quick ref capybara
Quick ref capybaraQuick ref capybara
Quick ref capybara
fatec
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
husnara mohammad
 
Haml
HamlHaml
Make your own wp cli command in 10min
Make your own wp cli command in 10minMake your own wp cli command in 10min
Make your own wp cli command in 10min
Ivelina Dimova
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
musrath mohammad
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
Tudor Constantin
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Dotan Dimet
 

What's hot (19)

Finding a Better Way to CSS: Navigating Sass with Compass
Finding a Better Way to CSS: Navigating Sass with CompassFinding a Better Way to CSS: Navigating Sass with Compass
Finding a Better Way to CSS: Navigating Sass with Compass
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
 
3 php forms
3 php forms3 php forms
3 php forms
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
Html Cheat Sheet
Html Cheat SheetHtml Cheat Sheet
Html Cheat Sheet
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using php
 
php $_GET / $_POST / $_SESSION
php  $_GET / $_POST / $_SESSIONphp  $_GET / $_POST / $_SESSION
php $_GET / $_POST / $_SESSION
 
Sass
SassSass
Sass
 
Quick ref capybara
Quick ref capybaraQuick ref capybara
Quick ref capybara
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
Everest
EverestEverest
Everest
 
Haml
HamlHaml
Haml
 
Make your own wp cli command in 10min
Make your own wp cli command in 10minMake your own wp cli command in 10min
Make your own wp cli command in 10min
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 

Viewers also liked

PHP for Grown-ups
PHP for Grown-upsPHP for Grown-ups
PHP for Grown-ups
Manuel Lemos
 
Masterpiece Video Productions
Masterpiece Video ProductionsMasterpiece Video Productions
Masterpiece Video Productionsmasterpiecevideo
 
What Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On WindowsWhat Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On Windows
Manuel Lemos
 
FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012
Nouh Walid
 
One year of FusionInventory
One year of FusionInventoryOne year of FusionInventory
One year of FusionInventoryNouh Walid
 
PHP In Brazil
PHP In BrazilPHP In Brazil
PHP In Brazil
Manuel Lemos
 
Succeeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects PresentationSucceeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects Presentation
Terry Freedman
 
Continuing Professional Development
Continuing Professional DevelopmentContinuing Professional Development
Continuing Professional Development
Terry Freedman
 
Bodypaintingworld
BodypaintingworldBodypaintingworld
Bodypaintingworldpc1951
 
Space Oddity Andrew Kolb
Space Oddity Andrew KolbSpace Oddity Andrew Kolb
Space Oddity Andrew Kolb
Daniel Vak
 
Pubblicita Playboy
Pubblicita PlayboyPubblicita Playboy
Pubblicita Playboypc1951
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
Manuel Lemos
 
Welcome To The Library
Welcome To The LibraryWelcome To The Library
Welcome To The Librarybhodes
 
GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011Nouh Walid
 
I Am The Future Of Journalism Because
I Am The Future Of Journalism BecauseI Am The Future Of Journalism Because
I Am The Future Of Journalism Because
Terry Freedman
 
Rifiuti E Inceneritori
Rifiuti E InceneritoriRifiuti E Inceneritori
Rifiuti E Inceneritori
pc1951
 

Viewers also liked (18)

PHP for Grown-ups
PHP for Grown-upsPHP for Grown-ups
PHP for Grown-ups
 
Masterpiece Video Productions
Masterpiece Video ProductionsMasterpiece Video Productions
Masterpiece Video Productions
 
What Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On WindowsWhat Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On Windows
 
FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012
 
簡報2
簡報2簡報2
簡報2
 
One year of FusionInventory
One year of FusionInventoryOne year of FusionInventory
One year of FusionInventory
 
PHP In Brazil
PHP In BrazilPHP In Brazil
PHP In Brazil
 
Succeeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects PresentationSucceeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects Presentation
 
Continuing Professional Development
Continuing Professional DevelopmentContinuing Professional Development
Continuing Professional Development
 
簡報2
簡報2簡報2
簡報2
 
Bodypaintingworld
BodypaintingworldBodypaintingworld
Bodypaintingworld
 
Space Oddity Andrew Kolb
Space Oddity Andrew KolbSpace Oddity Andrew Kolb
Space Oddity Andrew Kolb
 
Pubblicita Playboy
Pubblicita PlayboyPubblicita Playboy
Pubblicita Playboy
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
 
Welcome To The Library
Welcome To The LibraryWelcome To The Library
Welcome To The Library
 
GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011
 
I Am The Future Of Journalism Because
I Am The Future Of Journalism BecauseI Am The Future Of Journalism Because
I Am The Future Of Journalism Because
 
Rifiuti E Inceneritori
Rifiuti E InceneritoriRifiuti E Inceneritori
Rifiuti E Inceneritori
 

Similar to Sending E-mail that reaches the destination using PHP

PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
Ismail Mukiibi
 
dfhdf
dfhdfdfhdf
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
Nate Abele
 
05 File Handling Upload Mysql
05 File Handling Upload Mysql05 File Handling Upload Mysql
05 File Handling Upload Mysql
Geshan Manandhar
 
HTML::FormHandler
HTML::FormHandlerHTML::FormHandler
HTML::FormHandler
bbeeley
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
Dave Cross
 
Php mail program
Php mail programPhp mail program
Php mail program
pyingkodi maran
 
forms.pptx
forms.pptxforms.pptx
forms.pptx
asmabagersh
 
Send email
Send emailSend email
Send email
Joselito Catanes
 
How To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHPHow To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHP
Sudheer Satyanarayana
 
מ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכירים
מ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכיריםמ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכירים
מ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכיריםMiriam Schwab
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
Yoav Farhi
 
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrapNode mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Katy Slemon
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
 
Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Wildan Maulana
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
Yusuke Wada
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Indexwebhostingguy
 

Similar to Sending E-mail that reaches the destination using PHP (20)

PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
dfhdf
dfhdfdfhdf
dfhdf
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
05 File Handling Upload Mysql
05 File Handling Upload Mysql05 File Handling Upload Mysql
05 File Handling Upload Mysql
 
HTML::FormHandler
HTML::FormHandlerHTML::FormHandler
HTML::FormHandler
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Php mail program
Php mail programPhp mail program
Php mail program
 
Introduction to php web programming - get and post
Introduction to php  web programming - get and postIntroduction to php  web programming - get and post
Introduction to php web programming - get and post
 
forms.pptx
forms.pptxforms.pptx
forms.pptx
 
Send email
Send emailSend email
Send email
 
How To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHPHow To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHP
 
מ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכירים
מ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכיריםמ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכירים
מ-antispambot ועד zeroise – עשר פונקציות וורדפרס שאתם כנראה לא מכירים
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
 
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrapNode mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2
 
Ubi comp27nov04
Ubi comp27nov04Ubi comp27nov04
Ubi comp27nov04
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index
 
Security.ppt
Security.pptSecurity.ppt
Security.ppt
 

Recently uploaded

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Sending E-mail that reaches the destination using PHP

  • 1. Sending E-mail that reaches the destination Manuel Lemos mlemos@acm.org http://www.ManuelLemos.net/ http://www.phpclasses.org/mimemessage
  • 2. The problems Sending e-mail is fundamental ● PHP native support for sending e-mail is ● deficient The Internet e-mail standards are complicated ● Incorrectly composed messages are ● discarded Correctly composed messages are confused ● with SPAM
  • 3. Solution Ready to use PHP components for sending e‑mail PHPMailer ● PEAR Mail ● SWIFT mailer ● MIME message ● Etc. ●
  • 4. What is MIME? Multipurpose Internet Mail Extensions ● Standards for sending E-mail messages ● Defined by many RFC documents: Request ● For Comments New RFC document versions are compatible ● with past versions
  • 5. MIME message class PHP class to compose and send e-mail Sends messages with text and HTML using ● any character set Embeds related files: images, CSS, etc.. ● May attach multiple files ● Optimized for sending newsletters to many ● recipients
  • 6. Text message require('email_message.php'); $m = new email_message_class; $m->SetEncodedHeader('Subject', 'This is the subject'); $m->SetEmailEncodedHeader('From', 'john@here.com', 'John'); $m->SetEmailEncodedHeader('To', 'joe@there.com', 'Joe'); $text = “Hello Joe,nnThis is the message.”; $m->AddQuotedPrintableTextPart($text); $m->Send();
  • 7. HTML message $html = “<html><head><title>Messagm</title></head><body>Hello Joe,<br />n<br />nThis is the message.</body></html>”; $text = strip_tags($html); $m->CreateQuotedPrintableHTMLPart($html, '', $h); $m->CreateQuotedPrintableTextPart($text, '', $t); $alternatives = array($t, $h); $m->AddAlternativeMultipart($alternatives); $m->Send()
  • 8. HTML messages with embedded images $image=array( $m->CreateQuotedPrintableHTMLPart ($html, '', $h); 'FileName'=>'image.gif', 'Content-Type' => $text = strip_tags($html); 'automatic/name', $m->CreateQuotedPrintableTextPart 'Disposition'=>'inline' ($text, '', $t); ); $alternatives = array($t, $h); $e->CreateFilePart($image, $i); $m->AddAlternativeMultipart ($alternatives); $url = 'cid:'. $related = array( $alternatives, $m->GetPartContentID($i); $i, $html = quot;<html> ); <head><title>Message</title> $m->AddRelatedMultipart </head><body><img src=”$url” /> ($related); Hello Joe,<br />n<br />nThis is the message.</body></html>quot;; $m->Send()
  • 9. Message with attached files $attachment=array( 'Data'=>'This is an attachment called attachment.txt', 'Name'=>'attachment.txt', 'Content-Type'=>'automatic/name', 'Disposition'=>'attachment', ); $m->AddFilePart($attachment); $attachment=array( 'FileName'=>'attachment.zip', 'Content-Type'=>'automatic/name', 'Disposition'=>'attachment', ); $m->AddFilePart($attachment); $m->Send();
  • 10. Sending via SMTP Supports several types of authentication using the SASL classes: LOGIN, MD5, NTLM, etc. require('sasl.php'); require('smtp.php'); require('smtp_message.php'); $m = new smtp_message_class; $m->smtp_host = 'smtp.gmail.com'; $m->smtp_port = 465; $m->smtp_ssl = 1; $m->smtp_user = 'some_user'; $m->smtp_password = 'some_password'; $m->direct_delivery = 0;
  • 11. Sending via sendmail, qmail and Microsoft Exchange Faster delivery to the MTA queue require('sendmail_message.php'); $m = new sendmail_message_class; $m->delivery_mode = SENDMAIL_DELIVERY_DEFERRED; require('qmail_message.php'); $m = new qmail_message_class; require('pickup_message.php'); $m = new pickup_message_class;
  • 12. Mail() function alternatives When the mail() function does not work well smtp_mail() ● sendmail_mail() ● qmail_mail() ● urgent_mail() ●
  • 13. The path of the messages Local SMTP Local queue Destination queue SMTP Pickup PHP script MTA Destination SMTP mail() Direct
  • 14. The best delivery methods 1.Drop a message file in the local queue 2.Pass to MTA with the mail function (sendmail) 3.Pass to the local SMTP server 4.Direct delivery to the destination SMTP server
  • 15. Optimizing the delivery of non‑personalized newsletters $list = array( 'peter@here.com'=>'Peter', 'paul@there.com'=>'Paulo', 'mary@overthere.com'=>'Mary' ); $m->SetBulkMail(1); $m->cache_body = 1; foreach($list as $email => $name) { $m->SetEncodedEmailHeader('To', $email, $name); $m->Send(); } $m->SetBulkMail(0);
  • 16. Optimizing the delivery of personalized newsletters $m->SetBulkMail(1); $m->cache_body = 0; $template = 'Hello {name}, ...'; $m->CreateQuotedPrintableTextPart($template, '', $part_template); $m->AddPart($part_template); foreach($list as $email => $name) { $m->SetEncodedEmailHeader('To', $email, $name); $text = str_replace('{name}', $name, $template); $m->CreateQuotedPrintableTextPart($text, '', $personalized); $m->ReplacePart($part_template, $personalized); $m->Send(); } $m->SetBulkMail(0);
  • 17. Handling returned messages 1.Set the Return-Path message header to an address associated with a POP3 mailbox 2.Periodically poll that mailbox using a POP3 client class 3.Process the returned messages with the MIME parser class 4.Unsubscribe from the newsletters the e‑mail addresses that are returning the messages
  • 18. Know when a message was received Techniques that do not always work 1.Set the Disposition-Notification-To message header to an address to which reception notices will be sent 2.Insert a beacon image in an HTML message using the URL of a script that accounts messages that are viewed by recipients <img src=”http://www.meusite.com.br/conta.php?usuario=joao@ali.com.br”>
  • 19. Avoid confusion with SPAM What types of messages you should not send? ● Sent from an IP address without reverse DNS record (PTR) or that is listed in blacklists ● The recipient e-mail addresses are in Bcc Only with an HTML part or has invalid HTML ● With beacon image URL that has parameters ● Link URLs do not match anchor text URL ● Do not pass SpamAssassin checks ●
  • 20. Questions? Manuel Lemos mlemos@acm.org http://www.phpclasses.org/mimemessage
  • 21. References MIME Message class ● http://www.phpclasses.org/mimemessage SMTP client class ● http://www.phpclasses.org/smtpclass SASL authentication class ● http://www.phpclasses.org/sasl POP3 client class ● http://www.phpclasses.org/pop3class MIME parser class ● http://www.phpclasses.org/mimeparser Verify IP addresses in multiple blacklists ● http://openrbl.org/ SpamAssassin ● http://spamassassin.apache.org/