Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
Send Emails in PHP Using the Swift Mailer
Jun 12, 2018 @ 18:18:59

On the TutsPlus.com site, they've posted a new tutorial showing you how to use one of the more popular (and longest running) mailer projects in PHP: Swift Mailer. In this tutorial they introduce you to the tool and share some code showing it in use to send basic emails.

In this article, we're going to explore the Swift Mailer library that allows you to send emails from PHP applications. Starting with installation and configuration, we'll go through a real-world example that demonstrates various aspects of sending emails using the Swift Mailer library.

The article starts with a brief introduction to the Swift Mailer library and what kinds of features it brings to the table. It then shows the installation via Composer and how to include it into your application (autoloaded, naturally). Code is then provided showing how to send emails and includes examples of sending BCCs, attachments, setting the "from" and setting the body contents. It steps you through each part of this sample code and explains what it is doing and other options it could include.

tagged: tutorial send email swiftmailer introduction package composer

Link: https://code.tutsplus.com/tutorials/send-emails-in-php-using-the-swift-mailer--cms-31218

Joe Ferguson:
Mocking Swift Mailer – 3 Steps to better code
Dec 22, 2016 @ 16:46:43

If you're a user of the SwiftMailer package in your application, you may have hit on issues with your unit tests with mocking the library to isolate it from the actual email sending. Joe Ferguson is here to help with some advice in his latest post on mocking the library and how he used it to solve a problem in his own code.

A few days ago an issue came across my Jira queue that mentioned odd characters showing up in the subject line of our notification system. We use SwiftMailer library which is a fantastic library for sending mail.

[...] Something was taking our twig template that we use for our email subject and changing the encoding. This is normally done when you want to convert special characters so they’re not interpreted as code blocks. The example above is showing where an apostrophe is converted to “'”, the ASCII code equivalent.

He breaks the rest of the post into 3 steps (well, really 4 but there's a 2.5 in there) that he followed to mock the library out appropriately and be able to test the message sending without actually having to send. Code examples are included of both the code doing the sending and the test doing the mocking and verifying the subject lines on their emails (the original bug reported).

tagged: mocking unittest swiftmailer package test tutorial

Link: https://www.joeferguson.me/mocking-swift-mailer-3-steps-to-better-code/

SitePoint PHP Blog:
Mail Logging in Laravel 5.3: Extending the Mail Driver
Sep 26, 2016 @ 16:54:40

On the SitePoint PHP blog there's a new tutorial posted by Younes Rafie looking at logging of mail handling in Laravel by extending the already included driver with your own updates.

One of the many goodies Laravel offers is mailing. You can easily configure and send emails through multiple popular services, and it even includes a logging helper for development.

[...] Laravel also provides a good starting point for sending mails during the development phase using the log driver, and in production using smtp, sparkpost, mailgun, etc. This seems fine in most cases, but it can’t cover all the available services! In this tutorial, we’re going to learn how to extend the existing mail driver system to add our own.

They start by helping you create the service provider used to log the mail information to a database table (the DBMailProvider). The extend the existing mail provider class and set it up to register the Swift Mailer provider if the configuration for the mailer is not set to "db". The the tutorial shows how to update the provider to override the swift.mailer instance in the application dependency injection container and include the code to override the "send" method. A migration is created to hold the mail data and a matching Emails model is used to save the mail results.

tagged: laravel email logging database tutorial driver swiftmailer configuration

Link: https://www.sitepoint.com/mail-logging-in-laravel-5-3-extending-the-mail-driver/

Gonzalo Ayuso:
Sending automated emails with PHP, Swiftmailer and Twig
Sep 24, 2013 @ 16:40:57

Gonzalo Ayuso has posted a new tutorial today showing you how to combine PHP, Swiftmailer and Twig to send automated emails from your application.

My work as host is basically pick the place and encourage people to join to the Coding Dojo. One way of doing this (besides twitter buzz) is take my address book and send one bulk email to all of them inviting to join us. I don't like this kind of mails. They look like spam, so I prefer to send a personalized email. This email has a common part (the place location, the hour, the event description, ...) and the personalized part. I can do it manually, the list isn't so huge, but definitely that's not cool. Because of that I have done a little script to perform this operation.

His example extracts the information from a simple spreadsheet exported as a CSV file. He creates a simple Mailer class that uses Swiftmailer to do the actual sending. You pass in the Twig rendering object (Twig_Environment) that's used to render the email output. He includes a "Spammer" class that uses the Symfony EventDispatcher to send the email if everything works or an error email if something fails. He then drops it all into a Symfony Console command structure, defines several configuration settings in a "config.yml" and makes the script to execute the commands.

tagged: email swiftmailer twig template tutorial symfony console eventdispatcher

Link: http://gonzalo123.com/2013/09/23/sending-automated-emails-with-php-swiftmailer-and-twig

PHPMaster.com:
Sending Email with Swift Mailer
Dec 04, 2012 @ 17:34:54

On PHPMaster.com today there's a new tutorial showing you how to use Swift Mailer, a popular (and well-established) mailing tool.

Sending emails programmatically is a common task that programmers must deal with often. Although you can use PHP’s native functions, they can be too low-level, especially when you want to attach one or more files to your message. If you don’t want to use the native functions, or if you want to send mail using an object-oriented approach, then this is the article for you. I’ll introduce you to Swift Mailer, a powerful component-based library that let’s you send emails easily. Started in 2005, Swift Mailer is a library that provides several classes that allow you to send emails from within your PHP scripts or web applications.

Included in the post are a basic example of sending a plain-text email, working with attachments and including a template into the body of the message (with spots to fill text in).

tagged: swiftmailer introduction tutorial email pear

Link:

Sebastian Göttschkes:
symfony2: Testing email sending
Sep 13, 2012 @ 13:52:03

Sebastian Göttschkes has a new post showing a method he's come up with to test email sending in a Symfony2 application.

On my endless struggle to achieving 100% code coverage and catching every possible (and impossible) test case (I'm just kiddinh, please don't do this!) I was in need for some way to test the sending of emails. This blog post will show you how to test this within a symfony2 (I'm using symfony 2.1 RC2) application, using the default swiftmailer.

It's not unit testing, it's functional testing, and he provides a bit of background on the process first then sets up a dummy listener for testing and how to plug in the Symfony2 functionality (via a getContainer call to get the DIC).

tagged: symfony2 swiftmailer testing webtest email send

Link:

Web Development Blog:
PHP Mail Scripts using SMTP transport, a guide for beginners
Apr 12, 2010 @ 15:47:47

From the Web Development Blog today there's a new tutorial showing you how to use STMP from PHP via one of three different tools - the Zend_Mail component of the Zend Framework, SwiftMailer and PHPMailer.

PHP has a very simple mail function which is used very often for basic text mail messages. What if you need to attach files or if you need to send your e-mail messages via SMTP? Than it’s time to use a more advanced script. This is because the standard mail function has only limited standard capabilities.

Snippets of code are included for each of the three showing how to send a simple email with the usual "To", "From" and body contents. All of the tools have the ability to include attachments, but that's not included here.

tagged: smtp tutorial beginner swiftmailer zendmail phpmailer

Link:

Fabien Potencier's Blog:
Swift Mailer Takeover
Sep 17, 2009 @ 15:44:03

As is mentioned in the latest post to his blog, Fabien Potencier has taken over as the project manager for the SwiftMailer project:

This is a great honor for me to take over such a project. The Swift Mailer project has been initiated by Chris Corbyn some years ago. He has done a wonderful job during the years, trying to find the best way to create a top-notch emailing solution for PHP. With the release of the 4th version of Swift Mailer earlier this year, I think we now have a very solid mailing library.

As a part of the effort to expand the use of the mailing library, it will become the default emailing solution for the Symfony framework. You can learn more about Swift Mailer from the project's website.

tagged: swiftmailer symfony project manager

Link:

PHPImpact Blog:
From Swift Mailer to Zend_Mail
Jun 27, 2008 @ 12:55:48

On the PHP::Impact blog, there's a new post talking about his conversion from Swift Mailer over to the Zend_Mail component of the Zend Framework.

I've recently switched from Swift Mailer to Zend_Mail and, to be honest, I'm loving it. Finally someone developed a lightweight, powerful and easy to use Mail component!

He includes an example or two showing a basic mailer script, one that uses a fluent interface, one sending an HTML email and two that show how to use a remote SMTP server.

tagged: zendmail swiftmailer change example tutorial zendframework

Link:

Symfony Blog:
How to send emails in symfony 1.1
Jun 12, 2008 @ 15:25:29

On the Symfony blog, there's a new post showing the answer to a common question framework users have - what's the best way to send emails from inside our framework applications.

Sending mails is a web developer's everyday task, and symfony 1.1 let you do this easier than ever using Swift Mailer. Swift Mailer is a well thought, fully featured PHP5 object library that will cover 120% of your mailing needs.

They show how to create a partial or a component in your application that generates the content for the emails and pushes that result out to the Swift Mailer application. They show the (simple) installation from a svn checkout and two examples of sending emails, one simple and another with a multipart message.

tagged: send email symfony framework swiftmailer component tutorial

Link:


Trending Topics: