SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
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/

Mais conteúdo relacionado

Mais procurados

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 CompassClaudina Sarahe
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようDaisuke Komatsu
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
Html Cheat Sheet
Html Cheat SheetHtml Cheat Sheet
Html Cheat Sheetbrighteyes
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using phpRishabh Srivastava
 
php $_GET / $_POST / $_SESSION
php  $_GET / $_POST / $_SESSIONphp  $_GET / $_POST / $_SESSION
php $_GET / $_POST / $_SESSIONtumetr1
 
Quick ref capybara
Quick ref capybaraQuick ref capybara
Quick ref capybarafatec
 
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 10minIvelina Dimova
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners musrath mohammad
 
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
 

Mais procurados (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)
 

Destaque

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 WindowsManuel Lemos
 
FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012Nouh Walid
 
One year of FusionInventory
One year of FusionInventoryOne year of FusionInventory
One year of FusionInventoryNouh Walid
 
Succeeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects PresentationSucceeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects PresentationTerry Freedman
 
Continuing Professional Development
Continuing Professional DevelopmentContinuing Professional Development
Continuing Professional DevelopmentTerry Freedman
 
Bodypaintingworld
BodypaintingworldBodypaintingworld
Bodypaintingworldpc1951
 
Space Oddity Andrew Kolb
Space Oddity Andrew KolbSpace Oddity Andrew Kolb
Space Oddity Andrew KolbDaniel 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 PluginsManuel 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 BecauseTerry Freedman
 
Rifiuti E Inceneritori
Rifiuti E InceneritoriRifiuti E Inceneritori
Rifiuti E Inceneritoripc1951
 

Destaque (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
 

Semelhante a Sending E-mail that reaches the destination using PHP

The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
05 File Handling Upload Mysql
05 File Handling Upload Mysql05 File Handling Upload Mysql
05 File Handling Upload MysqlGeshan Manandhar
 
HTML::FormHandler
HTML::FormHandlerHTML::FormHandler
HTML::FormHandlerbbeeley
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
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 PHPSudheer 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 ZeroizeYoav 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; mailtrapKaty 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-KjaerCOMMON 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
 
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
 

Semelhante a 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
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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/