Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If a single page request generates multiple emails which contain the same images (e.g. a common email header image), the image only appears in the first email generated.
e.g. I have a custom module which allows anonymous users to register for an event. This creates a user account (and therefore sends a registration email) and registers the user for the event (which sends an event registration email). Both emails should have a common header and footer image, but only the first email includes them.
Comment | File | Size | Author |
---|---|---|---|
#2 | mimemail-634210-2271220.patch | 292 bytes | Mark B |
Comments
Comment #1
Mark B CreditAttribution: Mark B commentedI've tracked this down to the _mimemail_file function in mimemail.inc
This function maintains two static arrays of referenced files which have been generated for the email being built:
$filenames = the names of the files which have been referenced and built
$files = the content of the files
When the email has been completely built, the function is called again, and the $files array is returned and cleared. However, the $filenames array is not cleared. This means that if a second email is built, the static $filenames array thinks that common files have already had their content built. However, their corresponding entry in $files has been cleared.
The solution is to clear the $filenames array at the same time as the $files array is cleared once the email has been completely built.
Comment #2
Mark B CreditAttribution: Mark B commentedPatch file attached. Patch created against 6.x-1.0-alpha1, but bug exists in latest dev version too (which confusingly seems to be dated earlier than the 6.x-1.0-alpha1 release)
Comment #3
Mark B CreditAttribution: Mark B commentedComment #4
Czollli CreditAttribution: Czollli commentedThanks, it works fine!
Comment #5
Czollli CreditAttribution: Czollli commentedHi Mark,
I don't really understand the reason of array reinitialization
at the and, because these arrays marked static.
Before I have found your patch I removed the $files=array() line
and it also worked.
Or is it a special reason to do that?
Czollli
Comment #6
kurkuma CreditAttribution: kurkuma commentedIt works fine :-)
Comment #7
roball CreditAttribution: roball commentedCan someone please advise how to get an image (header logo) sent with the HTML mail? I'm using Simplenews together with Mime Mail, using the "html" Newsletter format. The HTML is generated using Wysiwyg API together with tinymce.
Thanks.
Comment #8
cafuego CreditAttribution: cafuego commented@roball Use the simplenews_template module
Comment #9
cafuego CreditAttribution: cafuego commentedSpeaking of simplenews_template, the patch attached above fixes the problem for images embedded in the node content, but seems to not fix the issue for images as defined in the simplenews_template header and footer.
In fact the header and footer images don't even get replaced with an inline tag anymore, but just disappear after I apply this patch.
Comment #10
roball CreditAttribution: roball commentedThanks cafuego! However, I can't get that module to work with the 2.x version of Simplenews - see #660662: Working with Simplenews 6.x-2.x-dev
Comment #11
cafuego CreditAttribution: cafuego commentedI'm not using simplenews 2.x-dev, but stable version 6.x-1.0.
Comment #12
roball CreditAttribution: roball commentedcafuego, sorry for the confusion - the additional fieldsets provided by Simplenews Template are now visible with Simplenews 6.x-2.x-dev.
Comment #13
Peter Bex CreditAttribution: Peter Bex commentedPlease make a bugfix release (1.1), as this is a major problem with this module which should really not be allowed to exist for so long in a stable version.
Comment #14
acb CreditAttribution: acb commentedThis is not fixing my problem; first mail gets sent with attachment intact; second gets sent with no attachment but the cid number below the mail.
Comment #15
cafuego CreditAttribution: cafuego commentedWhen I apply the patch, the attachments (and images) now work properly with simplenews 1.0
Comment #16
acb CreditAttribution: acb commentedCafuego, some questions:
1) are your images in the body of the node?
(I have not tested w. attached images)
2) Are they absolute or relative URLs?
Absolute URls in the node work (as images are not embedded in emails) The relative URLs do not get embedded in newsletters after the first one.
Comment #17
cafuego CreditAttribution: cafuego commentedHmm. why isn't my reply here.
@abc:
1) My images are in the body of the node and in the bodies of additional nodes I add via the related_content module.
2) The URLs are absolute from the site root. They do not include the entire !site_url as well.
Comment #18
acb CreditAttribution: acb commentedRight; if you use relative URLs you get the error, I think
Comment #19
bkonetzny CreditAttribution: bkonetzny commentedResetting $filenames at the same time $files is reset in _mimemail_file() fixed the problem with missing files on batch e-mail operations. Thanks!
Comment #20
acb CreditAttribution: acb commentedcould you post your code? Are you using relative or absolute URLs?
Are your files attached or are they in the body of the message?
Comment #21
sgabe CreditAttribution: sgabe commentedMarking as duplicate of #358439: Images are only in the first message.