Join David Powers for an in-depth discussion in this video Using the exercise files, part of PHP Email with Swift Mailer.
- View Offline
- If you're a member of the Lynda.com online training library, you have access to the exercise files for this course. Download them from the course page and save them in a convenient place on your local computer. I've got them here on my desktop, let's just open them. And all the exercise files are organized in folders, numbered after each chapter. And inside are subfolders for the individual videos that require exercise files.
When a file is in a different state at the end of the video, underscore and is appended to the file name. However for the case study in chapter six, the organization is slightly different. Let's just open this folder here. There are two subfolders in there, begin and end. Showing the files in the state at the beginning and end of the video. Chapter one concentrates on installing Swift Mailer. The next four chapters explain how to use Swift Mailer.
Beginning with the basics, attaching files, HTML email, and more advanced features. The examples are deliberately simple. Often sending only a single sentence as the message. The case study in chapter six draws everything together, sending individualized HTML emails with an embedded image from an online form to different addresses. In addition to the chapter related folders, there's a folder called includes that contains a single file called config.php.
This is an important file, so let's take a look at it in my editing program. This is the only version of config.php that's supplied with the exercise files. You need to fill in the definitions of the variables yourself to suit your own set up. The first variable on line seven is the location of an autoloader script. As you'll learn in chapter one, the way you choose to install Swift Mailer affects your directory structure. So defining the location here means the exercise files will work correctly for every setup.
I give detailed instructions on where to find the autoloader script in chapter one. The other variables are for the login details for your mail server. And for email addresses that you plan to use for testing. As well as my private email, I created a total of five email addresses, to test various aspects of working with Swift Mailer. And test one and testing were both the same email address, but in different formats.
The first one as an array, with the email address and name. And the second one with just the email address. If you don't have access to a lot of email addresses, just two will do. I explained this setup in more detail in chapter two. Some editing programs automatically collapse multi-line comments. So if the comments are collapsed like this when you open the file, just expand them. You might also find that your editing program collapses the inline CSS in the HTML examples.
In my editing program, clicking the ellipses expands the styles. One of the many advantages of Swift Mailer is that as long as you use an SMTP server, you can test sending email from a local testing environment. So copy the six chapter folders and the includes folder to a folder called php email in your testing server root. And you should be ready to go. I've got them all set up here, like that. I recorded most of this course on Windows, but I switched to MAC OS X to demonstrate a couple of features that won't work in a local Windows environment.
If you're a Windows person, just watch along. We'll test those features on your remote server. One final point, connecting to a remote mail server from a local testing environment might take several seconds. And email delivery could take much longer. During the editing process, we've speeded up any long pauses. Be patient when doing your own testing. And remember, in a real world application, your web server and mail server will be local to each other.
Making communication almost instantaneous.
Swift Mailer is free and feature-rich, and it integrates into any web app written in PHP 5 or 7. Swift Mailer offers a flexible and elegant object-oriented approach to sending emails, including HTML email and bulk email. This PHP tutorial guides developers through the process of installing and loading Swift Mailer, and sending emails using SMTP and encrypted SMTP connections. David Powers teaches secure methods that protect users and support MIME standards. He also introduces advanced techniques for sending attachments, personalizing email, and limiting the send rate. Want to see how Swift Mailer solves a real-world programming challenge? Chapter 6 is a case study that shows how to use Swift Mailer to send an email registration form.
- What is Swift Mailer?
- Installing Swift Mailer
- Preparing basic email
- Sending email via SMTP
- Handing off emails to mail transport agents
- Sending attachments
- Sending HTML email
- Personalizing bulk mail
- Limiting the rate of sending emails