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 use SMTP with Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to set timeout with Swiftmailer?
- Swiftmailer usage example
- How to configure Swiftmailer for SMTP without authentication?
- How to use Swiftmailer with SendGrid?
- How to get the response code when using Swiftmailer?
- How to send emails in UTF8 using Swiftmailer?
- How to set the reply to address in Swiftmailer?
- How to set the sender name in SwiftMailer?
See more codes...