Title: Binary Attachments
Last modified: November 21, 2022

---

# Binary Attachments

 *  Resolved [Malcolm](https://wordpress.org/support/users/malcolm-oph/)
 * (@malcolm-oph)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/binary-attachments/)
 * I’ve been trying out FluentSMTP with an upcoming release of my StageShow plugin,
   and I have experienced a problem. With basic emails it works fine, but my plugin
   sends emails that can have a couple of embedded images and with these FluentSMTP
   fails. One image (a logo) is read from a file and the other (a Barcode) is generated“
   on the fly” and passed to the Mailer as a binary image. In both cases the images
   are added by calling public methods of the PHPMailer class (addEmbeddedImage 
   and addStringEmbeddedImage respectively) in an action handler of the phpmailer_init
   action. My implementation works fine with the default WP Mailer (PHPMailer).
   
   I’ve configured FluentSMTP to use a SMTP Server and the test email works fine.
   However the emails with the Barcode do not get sent, an exception is thrown and
   the action handler of the wp_mail_failed action is being called. The error object
   does not appear to have any useful data. If I comment out the call to addStringEmbeddedImage,
   the email is sent successfully, so I suspect that FluentSMTP has a problem with
   attachments that are added as binary images rather than a file path. I’ve had
   a look at the FluentSMTP code and think I may have found the problem. In app/
   Services/Mailer/Providers/Smtp/Handler.php. line 98 calls addAttachment() passing
   $attachment[0] as the first parameter. This function expects a file path, but
   for attachments added as an image this element is the image of the file (there
   is no file path as there is no file), and therefore function throws an exception.
   It also looks like the other contents of the attachment element are ignored, 
   so my setting of the disposition to “inline” is lost. Is this something that 
   you are aware of? Would you expect FluentSMTP to be able to handle attachments
   added by the addStringEmbeddedImage method? Many Thanks
    -  This topic was modified 3 years, 6 months ago by [Malcolm](https://wordpress.org/support/users/malcolm-oph/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Malcolm](https://wordpress.org/support/users/malcolm-oph/)
 * (@malcolm-oph)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/binary-attachments/#post-16222187)
 *     ```
       I have some extra info on the above.
       Changing my plugin code so my binary image is stored in a temporary file, and adding this to the PHPMailer object stopped FluentSMTP throwing an exception, however the resulting email had my embedded images as attachments rather than inline images. Adding the extra elements in the addAttachments call fixed that. Note that I’ve changed the second parameter to $attachment[2] rather than $attachment[7] which is the CID for inline elements. Here’s the updated code:
       ```
   
 * $this->phpMailer->addAttachment(
    $attachment[0], // Path $attachment[2], // 
   Name $attachment[3], // Encoding $attachment[4], // Type $attachment[6] // Disposition);
 *     ```
       Attachments with binary content rather than a file path are still a problem.
       ```
   
 *  Thread Starter [Malcolm](https://wordpress.org/support/users/malcolm-oph/)
 * (@malcolm-oph)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/binary-attachments/#post-16226510)
 * Here’s what I believe is a complete fix for both binary data and disposition 
   problems identified above:
 *     ```
       foreach ($attachments as $attachment) {
       	if ($attachment[5]){
       		// This is a string/binary attachment
       /*
       		attachment elements:
   
               0 => string/image
               1 => name
               2 => name
               3 => encoding
               4 => type
               5 => isStringAttachment (true)
               6 => disposition
               7 => cid
       */
               $this->phpMailer->addStringEmbeddedImage(
               	$attachment[0], 	// Image
               	$attachment[7],		// CID
               	$attachment[2],		// Name
               	$attachment[3],		// Encoding
               	$attachment[4],		// Type
               	$attachment[6]		// Disposition
               	);
       	}
       	else {
       		// This is a file attachment
       /*
       		attachment elements:
   
               0 => path
               1 => filename
               2 => name
               3 => encoding
               4 => type
               5 => isStringAttachment (false)
               6 => disposition
               7 => name
       */
               $this->phpMailer->addAttachment(
               	$attachment[0], 	// Path
               	$attachment[2],		// Name
               	$attachment[3],		// Encoding
               	$attachment[4],		// Type
               	$attachment[6]		// Disposition
               	);
       	}
       }
       ```
   
 * I hope that you find it useful.
 *  Plugin Support [Amimul Ihsan](https://wordpress.org/support/users/amimulihsanmahdi/)
 * (@amimulihsanmahdi)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/binary-attachments/#post-16230167)
 * Hello [@malcolm-oph](https://wordpress.org/support/users/malcolm-oph/),
 * Would you please mention which email-sending service you are using?
 * Let me know the update.
 * Thank you
 *  Thread Starter [Malcolm](https://wordpress.org/support/users/malcolm-oph/)
 * (@malcolm-oph)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/binary-attachments/#post-16235093)
 * I have website hosting from Hostinger (hostinger.com). It’s the SMTP server for
   the Email accounts I get with that account.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Binary Attachments’ is closed to new replies.

 * ![](https://ps.w.org/fluent-smtp/assets/icon.svg?rev=2458343)
 * [FluentSMTP - WP SMTP Plugin with Amazon SES, SendGrid, MailGun, Postmark, Google and Any SMTP Provider](https://wordpress.org/plugins/fluent-smtp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/fluent-smtp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/fluent-smtp/)
 * [Active Topics](https://wordpress.org/support/plugin/fluent-smtp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/fluent-smtp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/fluent-smtp/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Malcolm](https://wordpress.org/support/users/malcolm-oph/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/binary-attachments/#post-16235093)
 * Status: resolved