--- a/html/modules/contrib/smtp/src/Plugin/Mail/SMTPMailSystem.php +++ b/html/modules/contrib/smtp/src/Plugin/Mail/SMTPMailSystem.php @@ -504,14 +504,18 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface { // Process mimemail attachments, which are prepared in mimemail_mail(). if (!empty($message['params']['attachments'])) { foreach ($message['params']['attachments'] as $attachment) { - if (isset($attachment['filecontent'])) { - $mailer->AddStringAttachment($attachment['filecontent'], $attachment['filename'], 'base64', $attachment['filemime']); - } - if (isset($attachment['filepath'])) { + if (!empty($attachment['filepath'])) { $filename = isset($attachment['filename']) ? $attachment['filename'] : basename($attachment['filepath']); $filemime = isset($attachment['filemime']) ? $attachment['filemime'] : file_get_mimetype($attachment['filepath']); $mailer->AddAttachment($attachment['filepath'], $filename, 'base64', $filemime); } + elseif (!empty($attachment['filecontent'])) { + // It is safer to use filecontent only when filepath is not available + // because filecontent attachments are prone to be deduplicated by + // the SMTP system, which would cause the duplicated attachments to be + // missing. + $mailer->AddStringAttachment($attachment['filecontent'], $attachment['filename'], 'base64', $attachment['filemime']); + } } }