Join David Powers for an in-depth discussion in this video Attaching a local file, part of PHP Email with Swift Mailer.
- View Offline
- [Voiceover] Although it's not impossible to use…the standard PHP mail function…to send an attachment, it's a lot of work.…With Swift Mailer though, it involves…only a few lines of code.…Swift Mailer can not only attach files that already exist,…it's also capable of attaching files…that are generated dynamically.…In this video, we'll deal with an existing file.…I've opened attachment.php, which you can find…in the chapter three, 03_01 folder,…of the exercise files.…
The same folder also contains a subfolder…called images and inside there is this image,…this PNG image, with a rather long file name.…I'm going to attach this image to the email…that I'm going to send from attachment.php.…So after preparing the email message,…we need to create the attachment.…So add in a few extra lines,…and we're attaching a local file.…Then we need a variable for the attachment…and we use the Swift_Attachment fromPath…static method and this expects the path to the file.…
So it's in the images folder,…and it's called elephpant…and then some numbers at the end.…
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