php-swiftmailerHow to add an attachment from a string using Swiftmailer?
Using Swiftmailer, you can add an attachment from a string by creating a Swift_Attachment
object and passing the string as the first parameter. The second parameter is the filename of the attachment.
Example code
$attachment = Swift_Attachment::newInstance($string, 'filename.txt');
The code above will create a new attachment object with the string as the content and the filename as the second parameter.
Code explanation
Swift_Attachment::newInstance()
: creates a new attachment object$string
: the string to be attached'filename.txt'
: the filename of the attachment
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...