Message / Header, Body Header / Body code sample From $message->setFrom('[email protected]'); Subject $message->setSubject('This is sample'); To, Cc, Bcc $message->setTo('[email protected]')! ->setCc('[email protected]')! ->setBcc('[email protected]');! Body $message->setBody('Hello World');
Message / AddPart / Sample $message = Swift_Message::newInstance();! $message! ->setFrom(MAIL_FROM)! ->setTo(MAIL_TO)! ->setSubject('Multipart mail sample')! ;! ! // POINT of this sample! $message->addPart(! 'This is TEXT part.',! 'text/plain'! );! $message->addPart(! 'This is HTML part.',! 'text/html'! );
Transport / SMTP / Samples // POINT of this sample! $transport = Swift_SmtpTransport::newInstance(! SMTP_HOST,! SMTP_PORT! );! $mailer = Swift_Mailer::newInstance($transport);
Transport / Sendmail / Sample // POINT of this sample! $transport = Swift_SendmailTransport::newInstance(! '/usr/sbin/sendmail -bs'! );! // -bs means 'Stand-alone SMTP server mode'! ! $mailer = Swift_Mailer::newInstance($transport);
Transport / Mail / Sample // POINT of this sample! $transport = Swift_MailTransport::newInstance();! $mailer = Swift_Mailer::newInstance($transport);! !
Mailer FailoverTransport Transport / Failover missing ! SmtpTransport 1 SMTP Server 1 SmtpTransport 2 SmtpTransport n SMTP Server 2 SMTP Server n Usually use SMTP Server1. When Server 1 goes down, use Server 2.
Mailer FailoverTransport Transport / Loadbalanced missing ! SmtpTransport 1 SMTP Server 1 SmtpTransport 2 SmtpTransport n SMTP Server 2 SMTP Server n Used in rotation from SMTP Server 1 to STMP Server n
Transport / Null / Sample // POINT of this sample! $transport = Swift_NullTransport::newInstance();! $mailer = Swift_Mailer::newInstance($transport); missing !
Transport / FileSpool missing ! Mailer SMTP Server SpoolTransport FileSpool Storage File 1 File 2 File 3 File n Not send Create one file by one mail. ! Each files are Swift_Message serialized object.
Transport / MemorySpool missing ! Mailer SMTP Server SpoolTransport MemorySpool Memory $array[0] $array[1] $array[3] $array[n] Not send Add one element to array by one mail.
Transport / MemorySpool / Sample // POINT of this sample! $spool = new Swift_MemorySpool();! $transport = Swift_SpoolTransport::newInstance($spool);! ! $mailer = Swift_Mailer::newInstance($transport);! missing !
Plugin / AntiFlood ! Mailer SmtpTransport SMTP Server AntiFloodPlugin Re-connect to SMTP Server in every 100 emails (100 is default). You may want to sleep a specified number of seconds. re-connect
Plugin / AntiFlood / Sample // POINT of this sample! // re-connect by 1 send, and 10 sec sleep (option)! $mailer->registerPlugin(! new Swift_Plugins_AntiFloodPlugin(1, 10)! );
Plugin / Throttler ! Mailer SmtpTransport SMTP Server ThrottlerPlugin This can limit the number of transmissions per minute, second or bytes. ex. 100 mails per minute
Plugin / Throttler / Sample // POINT of this sample! // 1 send per minute! $mailer->registerPlugin(! new Swift_Plugins_ThrottlerPlugin(! 1,! ɹɹ Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE! )! );
Plugin / Logger Mailer SmtpTransport SMTP Server LoggerPlugin ArrayLogger Display logs used dump() method. Logging to array. EchoLogger or Echo each process log.
Plugin / Logger / Sample // POINT of this sample! // store log to array! $logger = new Swift_Plugins_Loggers_ArrayLogger();! $mailer->registerPlugin(! new Swift_Plugins_LoggerPlugin($logger)! );! ! [snip]
$result = $mailer->send($message);! ! // POINT of this sample! echo $logger->dump();
Plugin / Impersonate example.com SMTP Server example.jp SMTP Server errors.example.jp SMTP Server Bounced mails return to errors.example.jp Using ImpersonatePlugin
Plugin / Impersonate / Sample // POINT of this sample! // Replace 'Return-path' to $sender! $sender = MAIL_SENDER;! $mailer->registerPlugin(! new Swift_Plugins_ImpersonatePlugin($sender)! ); missing !
Plugin / Redirecting / Sample // POINT of this sample! // All recipients are replace to $recipient.! // Except a pattern in whitelist.! $recipient = MAIL_REDIRECT_TO;! $whiteList = [WHITE_LIST_PCRE_PATTERN];! ! $mailer->registerPlugin(! new Swift_Plugins_RedirectingPlugin(! $recipient,! $whiteList! )! ); missing !
Plugin / Reporter missing ! Mailer SmtpTransport SMTP Server ReporterPlugin HitReporter Find a failed recipients using FailedRecipients() method. HtmlReporter or Reporting success or failed recipients by HTML format.
Plugin / Reporter / Sample // POINT of this sample! $reporter = new Swift_Plugins_Reporters_HitReporter();! $mailer->registerPlugin(! new Swift_Plugins_ReporterPlugin($reporter)! );! ! $recipients = [MAIL_TO, MAIL_FAILED_ADDRESS];! foreach ($recipients as $recipient) {! $message->setTo($recipient);! $result = $mailer->send($message);! }! ! // POINT of this sample! $failedRecipients = $reporter->getFailedRecipients();! var_dump($failedRecipients); missing !
Transport / Amazon SES / Sample // POINT of this sample! $transport = Swift_AWSTransport::newInstance(! AWS_ACCESS_KEY,! AWS_SECRET_KEY! );! $transport->setEndpoint(AWS_ENDPOINT);! $mailer = Swift_Mailer::newInstance($transport);
Plugin / Filter / Sample use Openbuildings\Swiftmailer\FilterPlugin;! ! [snip]! ! // POINT of this sample! // set email address or domain! $whiteList = [MAIL_TO];! $blackList = [MAIL_TO2];! $mailer->registerPlugin(! new FilterPlugin($whiteList, $blackList)! );
Plugin / CSS Inliner / Sample use Openbuildings\Swiftmailer\CssInlinerPlugin;! ! [snip]! ! // POINT of this sample! $mailer->registerPlugin(! new CssInlinerPlugin()! );!
Plugin / Google Campaign / Sample use Openbuildings\Swiftmailer\GoogleCampaignPlugin;! ! // POINT of this sample! $mailer->registerPlugin(! new GoogleCampaignPlugin([! 'utm_source' => 'source',! 'utm_campaign' => 'email',! 'utm_medium' => 'email',! ])! );
Appendix name URL Swift Mailer http://swiftmailer.org/ Amazon SES Transport https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES Filter Plugin https://github.com/OpenBuildings/swiftmailer-filter CSS Inliner Plugin https://github.com/OpenBuildings/swiftmailer-css-inliner Google Campaign Plugin https://github.com/OpenBuildings/swiftmailer-google-campaign Composer https://getcomposer.org/ Packagist https://packagist.org/