1. Todd Williams
  2. CMandrill for Joomla
  3. Monday, 23 September 2013
  4.  Subscribe via email
Hi!

I just figured I'd pass along a quick little hack that will allow image attachments to take advantage of the new "image" tag that is part of the Mandrill API.

In the mail.php plug-in script add a new array for image attachments. I called mine "$iAttachments"


private function mandrillSend()
{
$action = 'send';
$to = array();
$attachments = $this->GetAttachments();
$mAttachments = array(); //file attachments
$iAttachments = array(); //image attachments //<--- add this image array
if(count($attachments) > 0) {


Add an "image" match conditional on $mime_type as shown below:


if(count($attachments) > 0) {

foreach($attachments as $attachment) {
// a lot of people are setting wrong mime_type when using the addAtachment function
// let us try to determine the mime_type ourselves on the base of the filename
//
$mime_type = $this->detectMimeType($attachment[1]);
if(!$mime_type) {
$this->writeToLog(JText::sprintf('PLG_SYSTEM_MANDRILL_UNSUPPORTED_ATTACHMENT', $attachment[2], $mime_type));
// if one of the files is not an image/txt or pdf, then use standard phpmailer
// the mandrill api doesn't support other formats right now
$this->phpMailerSend();
};

//<--- look for attachments with mime type of "image"
//<--- add these images to the new $iAttachment array

if (preg_match('/^image/',$mime_type)) {
$iAttachments[] = array(
'name' => $attachment[2],
'type' => $mime_type,
'content' => $this->EncodeFile($attachment[0])
);

//<--- any other attachments get added to the original $mAttachments array, as per normal
} else {
$mAttachments[] = array(
'name' => $attachment[2],
'type' => $mime_type,
'content' => $this->EncodeFile($attachment[0])
);
}
}
}



Assign to the mandrill message object a new "images" array using the new $iAttachments


if(count($mAttachments)) {
$mandrill->message['attachments'] = $mAttachments;
}

//<--- assign $iAttachments to a new mandrill message "images" array.
if(count($iAttachments)) {
$mandrill->message['images'] = $iAttachments;
}



Now, image attachements will be given a "Content-Disposition" of "inline" as opposed to "attachment" and will display in html messages properly.

Regards,
-- williatf
Responses (1)
Daniel Dimitrov
Support team
Accepted Answer Pending Moderation
Hey Todd,
Thank you for this! I'll add this code to the next release!
Daniel
Please if you use our extensions be so kind and review them at JED
Matukio | Hotspots Pro | CComment Pro
  1. more than a month ago
  2. CMandrill for Joomla
  3. # 1
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Last questions

Is Ccomment still alive?
Is Ccomment still being supported? It's time for my Pro renewal but I haven't se...
0 Replies
Posted on Thursday, 14 August 2025
  • New
  • Anzeige von mehrtägigen Events auf Buchungsseite
    We have been using Matukio for quite some time now. Unfortunately, we have been ...
    3 Replies
    Posted on Sunday, 03 August 2025
    Assistance Needed – Error When Posting Comments
    Hello, I’m experiencing an issue when trying to submit a comment on my site u...
    0 Replies
    Posted on Sunday, 10 August 2025
  • New
  • Hotspots Pro 6.0.13 compatability with Joomla 5.3.
    Running Hotspots Pro 6.0.13 on Joomla 4.4.13 and want to upgrade to Joomla 5.3.1...
    2 Replies
    Posted on Friday, 04 July 2025
    some questions on Hotspots
    Hi, On Hotspots extension : 1) is it possible to add our own map layer / v...
    0 Replies
    Posted on Thursday, 03 July 2025