php-swiftmailerHow to add an attachment using Swiftmailer?
Swiftmailer is a popular library for sending emails in PHP. To add an attachment using Swiftmailer, you need to use the addAttachment()
method.
Example code
$message = (new Swift_Message('Hello World'))
->setFrom(['[email protected]' => 'John Doe'])
->setTo(['[email protected]', '[email protected]' => 'A name'])
->setBody('Here is the message itself')
->addAttachment(Swift_Attachment::fromPath('/path/to/file.pdf'));
The addAttachment()
method takes a Swift_Attachment
object as an argument. The Swift_Attachment
class provides several methods to create an attachment, such as fromPath()
which takes the path to the file as an argument.
Helpful links
More of Php Swiftmailer
- How to configure Swiftmailer for SMTP without authentication?
- How to log emails sent with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to send emails in UTF8 using Swiftmailer?
- How to set timeout with Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
- How to use Swiftmailer transport?
- How to use Swiftmailer with Symfony?
- How to get the response code when using Swiftmailer?
See more codes...