Closed (fixed)
Project:
Mime Mail
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Aug 2017 at 07:40 UTC
Updated:
2 Oct 2025 at 22:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
janehollander commentedHere's a patch which fixes those error messages that are displayed.
Comment #3
janehollander commentedComment #4
blake.thompson commentedThe patch in #2 worked for me, but there are a lot of fixes related to coding standards rather than this specific issue. Does it make more sense to create a separate issue for those changes? It was hard to decipher the changes related to just this bug.
Comment #5
tr commentedYes, this patch is MOSTLY coding standards fixes. And many of them are WRONG fixes which introduce new coding standards violations. This is really not the place to go back and forth about coding standards issues. Now that this module is using the testbot (see #2985803: Turn on testing for 8.x-1.x!) we can see and correct coding standards violations in separate patches.
So I've removed all the coding standards changes that were included in the patch from #2 and re-rolled it with just the functional changes related to this issue.
I must say that I don't think suppressing errors using @is_file is the right solution to this problem. Hiding the error doesn't actually fix anything ...
Comment #6
guerinteed_mike commented+ 1 Following
I am experiencing same issue.
There is not a whole lot of documentation on this issue. Is it possible to create test module?
thanks for the great module!!
Comment #7
tr commented@guerinteed_mike: Did you have the same issue? Did the patch fix it?
You don't need to post just to follow the issue - instead, click on the "Follow" link next to the star in the block in the upper right of this page.
Comment #8
guerinteed_mike commented@TR
Thank you for response. I will give it a shot within the next few days and let you know the turn out.
mikeg
Comment #9
tr commented@guerinteed_mike: Did the patch work for you?
Comment #10
guerinteed_mike commented@TR - I wanted to let you know this is still on my radar. Have not yet tried patch but will plan to get it to it next week
Comment #11
derekrezek commentedsame issue, i think patch #5 Should Fix the issue.
when a user creates an attachment in the format, e.g. :
what is happening is :
Comment #12
tr commentedHere's a re-roll of #5 to apply to the current HEAD.
Comment #13
imclean commentedAttaching files can be done by either passing the path to the file or passing the file contents directly. The issue summary doesn't state which method was used, although I suspect it's the latter. #11 refers to this method.
The code handling file attachments is a bit messy and tries to use the single variable
$fileto hold either a URL or the file contents, which it then strangely checks even though it will always be set. See:A better idea would be to treat
$fileand$contentas separate exclusive options. This could involve a a more comprehensive refactoring, but for a quick demonstration here's an alternate method of handling file content attachments.Comment #14
imclean commentedMinor tidy up.
Comment #15
aiphesHi,
I would apply this patch to get working emails with attachment via webform.
But I get an error message about outdated patch with the #14 version.
https://www.drupal.org/project/mimemail/issues/3127506
DFO I need to use another patch ? which one ?
If someone can help me.
Thanks
Comment #16
tr commented@aiphes: I answered your question in #3127506-7: Mimemail and Webform : attachment. The patch is good. You can verify that by looking at the testbot output in #14 where you'll see I re-triggered the test yesterday and verified the patch was good. I already told you this. The patch applies with git and with patch. This is not the place to get help with using some third-party development tool.
Comment #17
sgabe commented@aiphes: There is a "Version control" tab on the project page that provides basic instructions on how to use Git, please follow those when working with Drupal project source files.
Comment #18
aiphesThanks all, seem Tortoise isn't the right tool, will try with git command line (hope it do on windows machine)
Comment #19
tr commentedI am using Mime Mail for both the formatter and sender.
I tested PDF attachments with the new mimemail_example module (you will need the latest mimemail -dev for this). If you install this module then go to
example/mimemail_exampleand fill out the form, you can send a test e-mail with an attachment. This worked for me for attaching PDF files. No errors were generated in the log, and I received a properly formatted e-mail and was able to open the attachment and view the PDF file in my mail client.The mimemail_example module passes the file path, and only the file path, to the helper function. Specifically, in
MimeMailFormatHelper.php::mimeMailHtmlBody()line 142, the $attachments array contains:array( 0 => array ( 'filepath' => 'public://my_file.pdf', ), )As described by @imclean in #13, this is does not seem to be the way the error is triggered. Instead, it is triggered by passing in the file contents instead of the file path. I don't currently have a way to test that 'contents' method so I don't have a way to verify the bug and I don't have a way to see if #14 fixes the bug.
It would be great if someone would contribute some test code or better yet a test case to demonstrate this bug. That way we can fix it and have the test case to prove it is fixed ...
Likewise, if we had a test case, we could test that this works for both public and private files, embedded images, etc. As @imclean said in #13 the code is very messy and needs to be refactored, but I don't want to do that unless we have test cases to prove it's doing the right thing.
I think Kernel tests for all the MimeMailFormatHelper functions are badly needed.
Comment #20
imclean commentedHere's a quick overview of how we're using MIME Mail to send attachments.
Website content is created by the website owner (via REST, but can be manual). This includes a "Permit" content type which can have multiple documents attached as media entities. These documents are PDFs and are stored in the "private" file system to prevent direct access.
A customer can then purchase a permit. After payment, the relevant PDFs are emailed to the customer. This is done by loading the media entities then the file entities reference by the media entities.
The use of the private file system may have been the issue here.
This is an example of the type of code we're using.
Custom service:
my_module.module:Comment #21
imclean commentedI'll have a look at the example module to see if we can do something there.
Comment #22
imclean commentedI see you've changed the file handling a bit. I've updated the example module locally and it can handle attaching private files using the scheme
private://.I can also add an example of using the contents of a file to add an attachment. @TR, is this something you'd support?
Comment #23
tr commentedSure. I think the whole purpose of the mimemail_example module is to provide something useful for testing, debugging, and documenting - not only for site builders who are trying to integrate Mime Mail but also for development of Mime Mail, to test features and demonstrate bugs. Plus, it should serve as an example of how to use Mime Mail programmatically. I've already started using it to try to debug / reproduce issues in the issue queue, like this one, and to investigate support questions, and I think it's going to be very useful for people trying to get Mime Mail working on their own.
So anything you can contribute that will make it more useful would be appreciated. You can open new issues for each new feature, that way we can keep new features separate from bug reports and make sure you get credit for your contributions.
Comment #24
imclean commentedThe related issue demonstrates the problem seen here.
Comment #25
imclean commentedDouble post.
Comment #26
imclean commentedThis is still an issue. We're using the patch in #14. The problem can be demonstrated by the patch in #24 (which may need a re-roll).
What else needs to be done here?
Comment #27
imclean commentedSorry, I meant the problem can be demonstrated by the issue linked to in 24: #3129469: Support adding attachments as file contents
Comment #28
tr commentedWell, the bottleneck is me, but it's on my radar so it will get fixed ...
This issue IS a problem and the patch DOES prevent it, but this code is still really messed up and needs bigger fixes. We keep running into the same problems then slapping quick fixes on them, and the code becomes more and more of a patchwork that isn't documented, tries to do too much, and is still full of bugs. Take this issue as an example - we had the same problem in D7 (#2366659: Attachments created using 'content' instead of 'file' generate warnings) and the same problem in (#1850262: Sending content based mimemails), and we're still no closer making this code work properly. I really don't want to make another quick fix and hide an error.
What I want to do is rewrite
mimeMailFile(), but before I do that I need to ensure I'm not just trading one set of known problems that we have now for a new set of unknown problems with the rewrite. The way to do that is to have tests. But before the tests I need to understand what the code is *supposed* to do, and that's a problem with everything in MimeMailFormatHelper (which should really be a service rather than random static functions, BTW, but that's another issue entirely).Looking at
mimeMailFile(), the function name has nothing to do with its actual operation, it's documented as a "Helper function" but what "help" does it provide? It returns "The Content-ID and/or an array of the files on success or the URL on failure." - so that's a string, OR an array with an undocumented structure, OR a different string containing a URL. What? All the arguments are optional AND you have to call the function twice (ignoring the return value the first time, passing NO arguments the second time) for it to work properly?"@is_file" is used FOUR times in
mimeMailFile(), suppressing the error message each time means we've avoided seeing this problem or other related problems - instead we just hide them away until someone comes along with a slightly different case that exposes the problem again. This function usesmimeMailUrl()which is ALSO a "Helper function" with no documentation about what it does, so we don't know if that is doing the right thing or not (BTW, it's NOT doing the right thing currently either ...)I really can't support or maintain this piece of ... code without robust test cases. I've started doing that, and I've opened up a bunch of issues (e.g. #3145400: Add test cases for MimeMailFormatHelper::mimeMailFile()) and I'm slowly working my way through this. Since
mimeMailFile()usesmimeMailUrl(), I'd like to getmimeMailUrl()tested and fixed first becausemimeMailFile()won't work properly without it.In my local copy of MimeMailFormatHelper I have added a lot of documentation and general structural fixes, and I need to start pushing more of that out. But the big blocker is the tests - we need to get away from patching things without tests and we need to start having tests for everything - this has been Drupal core policy for like 10 years now.
The only thing you can do to speed up the process is to try to write some of the tests - for
mimeMailUrl()for example, or formimeMailFile(). I already have a lot of the rewrite done and will be making a bunch of small changes that fix the structure and specifically avoid the problem in this issue, but I don't have the tests yet and they tend to take a while to write even when the code is working, let alone when it's broken ...Comment #29
tr commented@imclean said:
Here are 17 issues over the years caused by this mess:
https://www.drupal.org/project/issues/mimemail?text=is_file&status=All&p...
This is why I want to fix this function, not just patch it.
I spent a few hours last night experimenting with this (giving mimeMailFile() input to see what it does), and I found even more problems which go back to Drupal 6 and have never been noticed before. I will be posting new issues and hopefully some tests for mimeMailFile() in the next few days.
Comment #30
imclean commented@TR,
This is why I took the approach I did in #14. But as you say, the entire "helper" needs rewriting. I'm still no closer to understanding the flow when attaching files, I just fixed an error where it occurred.
Comment #31
aiphesApplying patch #14 on fresh D8.9.13 install fix the warning :)
wget -q -O - https://www.drupal.org/files/issues/2020-02-04/mimemail_attachment_errors-2904611-14_0.patch | git applyin the module folder.Comment #32
mchamps commentedHi,
I'm running Drupal 9.3.3 and mimemail 8.x-1.0-alpha4
I have a similar error when sending and email with a PDF attachement from Webmail.
When I try to apply the patch with composer I get :
I also tried aiphes #31's method
wget -q -O - https://www.drupal.org/files/issues/2020-02-04/mimemail_attachment_errors-2904611-14_0.patch | git applyand get
I also tried with mimemail.dev and have the same errors.
I did not have this error with Drupal 8.9.19
Cheers
Comment #33
dbroll commentedI'm running Drupal 8.9.16 and mimemail 8.x-1.0-alpha4 (also tried the dev version)
I am getting both of the original errors, I tried patch 14 but it fails to apply.
Comment #36
dpiRebased/resolved conflicts as MR.
Comment #37
dpiI dont have this issues with PDF's, rather large files with specifically unrecognised characters are causing issues for
\realpath(), same as #32.Comment #38
imclean commented#32 and #37 is a separate issue. Let's keep this one focussed with a more accurate title.
The problem is Mime Mail using the same variable for either a file path or file contents. The errors occur when passing the file contents to
realpath()andis_file(). The error should not be hidden, instead the situation shouldn't arise in the first place.Comment #39
trakoczi commentedSince we would like to stick to alpha4 for now and switch to the dev branch, I have prepared the patch file for alpha4, in case anyone else needs it too.
Comment #40
tjtj commentedThe patch 39 does not fully apply on D9
patch -p1 < mimemail_attachment_errors-2904611-39.patch
patching file src/Utility/MimeMailFormatHelper.php
Hunk #1 succeeded at 5 with fuzz 2.
Hunk #2 FAILED at 393.
Hunk #3 FAILED at 417.
Hunk #4 succeeded at 649 with fuzz 2 (offset 3 lines).
2 out of 4 hunks FAILED -- saving rejects to file src/Utility/MimeMailFormatHelper.php.rej
Comment #41
tr commented@tjtj: No, you're wrong. As you can see, I triggered a re-test of the patch in #39 and the patch applies without a problem.
Of course, this patch still doesn't have any tests, so you can't tell whether it actually fixes anything, but the patch DOES apply.
The problem must be on your end - you may have an old version of this module, or you may have made local changes to the module code that conflict with the patch.
Comment #42
tjtj commentedI get in the reject file
In my file, I have
The patch does not have Drupal::config(. I downloaded the module today.
I will now try the dev version... YES, it worked.
Comment #43
mmmbsmm commentedHas anyone figured
yet? I am using mimemail and phpmailer smtp to send the attachment when you submit a webform but I am continuously getting this error. My test mail is sent to me successfully but it just wouldn't work in webform.
Comment #44
imclean commentedFor #32, #37 and #43, I've opened #3271547: Seeing errors when sending a mail with large files attached.
@mchamps, @dpi and/or @mmmbsmm could you please fill in some details in the issue summary. Specifically how to reproduce would be helpful.
Comment #45
imclean commentedComment #46
rdworianyn commentedThis doesn't resolve the issue, but I did find that a quick workaround is to instead output the file to a path, such as /tmp/myfile.pdf, and then use the following:
I just tested this using Drupal 9.4.0, Mime Mailer as the Formatter, and SMTP Mailer as the Sender, under the Mail System Module.
Comment #47
aiphesStill there with D9.4.8 + Mime Mail 8.x-1.0-alpha4
ValueError : realpath(): Argument #1 ($path) must not contain any null bytes dans realpath() (/home/xx-xx/www/xxx/sited9/web/core/lib/Drupal/Core/File/FileSystem.php ligne 139)Comment #48
sic commentedCome ooooooon
Comment #49
gaurav-mathur commentedI don't know how they are installing this module. The module is not compatible with D9 and D10 and patch #39 is not applied on drupal 9.4.x.I think this move need to be work .
Comment #50
tr commentedThis module absolutely IS compatible with Drupal 9. And it HAS been compatible with Drupal 9 for more than two years - since even before the official release of D9.
This module makes no claims that it is compatible with the brand-new release of Drupal 10 yet. If you want that to happen you can contribute here in the issue queue and help fix the known problems.
And again, I just retriggered the test in #39 and as you can see the testbot has absolutely no problem applying the patch. There is nothing wrong with the patch, the problem is on your end.
If you're interested in fixing this issue, then I think I've been pretty clear that there needs to be tests for this functionality. You can help.
Comment #51
aiphesHi,
As in #47, I still get this error with WSOD. v 8.x-1.0-alpha4
Do I need to patch the module or something else ?
Thanks
EDIT: patch doesn't fix the issue, will try with dev version
EDIT2: bad
my composer file:
:/ weird ?
Comment #52
tr commentedComment #53
qqboy commentedlocally, if I use
$params['attachments'][] = [
'filepath' => $file->getFileUri(),
];
avoided this patch, since this patch is stilled not imported to Module itself in alph-4.
Comment #54
mably commentedPatch #39 doesn't work with latest alpha5 :(
Comment #55
mably commentedTried to port #39 patch to alpha5 source code. Seems to work, not heavily tested though.
Comment #56
_tarik_ commented#55 +1 worked for me, PHP 8.1.16 - D9.5.8
Comment #57
kris77 commented#55 +1 worked for me to with latest alpha5.
Thanks @mably.
Comment #58
RyanCMcConnell commented#55 worked for me as well. Thank you @mably !
Comment #59
sinn commented#55 works well
Comment #60
kris77 commented#55 works for me too.
Thanks @mably
Comment #61
Bagz commented#55 works with alpha6 on Drupal 10.2.3 with PHP 8.2.16
Comment #62
betarobot commented#55 worked well with PHP 8.2.17 and Drupal 10.2.5.
Comment #63
heni_deepak commented#55 Work well with PHP 8.3.21 and Drupal 10.4.5
Thanks @mably
Comment #65
mark_fullmerThanks everyone, for the implementation, and for the reviews above. This has been merged.