php-swiftmailerHow to embed an image in Swiftmailer?
To embed an image in Swiftmailer, you need to use the Embed() method. This method takes the image file path as an argument and returns a Swift_Image object.
Example code
$image = $message->embed(Swift_Image::fromPath('path/to/image.jpg'));
Output example
Swift_Image Object
(
[_name:protected] => Swift_Image
[_file:protected] => path/to/image.jpg
)
Code explanation
$message: an instance ofSwift_MessageclassEmbed(): a method ofSwift_MessageclassSwift_Image: a classfromPath(): a static method ofSwift_Imageclass$image: a variable to store theSwift_Imageobject
Helpful links
More of Php Swiftmailer
- How to install Swiftmailer using Composer?
- How to configure Swiftmailer for SMTP without authentication?
- How to enable TLS with Swiftmailer?
- How to configure Swiftmailer for Postfix?
- How to access Swiftmailer logs?
- How to set the port for Swiftmailer?
- How to configure Swiftmailer logger?
- How to mock SwiftMailer?
- How to send HTML emails with Swiftmailer?
- How to use SMTP with Swiftmailer?
See more codes...