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 set timeout with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to get the response code when using Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
- How to configure Swiftmailer for Postfix?
- How to send emails in UTF8 using Swiftmailer?
- How to send emails to multiple recipients with Swiftmailer?
- How to set the port for Swiftmailer?
- How to enable TLS with Swiftmailer?
See more codes...