I am using Simplenews to create and send newsletters. Every time I send a newsletter to a sample of 5 recipients with Mime Mail set as the mail sending module, all recipients receive it but the body is blank. If I disable Mime Mail, the newsletter body text appears in the emails, but one recipient of the 5 does not receive the newsletter. The logs say all 5 emails were sent without any failures, although I also get a separate log message saying

Notice: Undefined offset: 0 in mimemail_html_body() (line 383 of /home/mysite/public_html/sites/all/modules/mimemail/mimemail.inc)

before each log entry for the emails.

My understanding is that Mime Mail is for sending HTML emails. To be fair I am not actually that bothered if recipients only get the newsletter in plain text, although this is a bit disappointing in terms of presentation. It's going to be very problematic however if on average 20% of recipients don't get the newsletter at all.

I've tried changing various Mime Mail settings, as well as setting the newsletter format to plain text within the Simplenews settings, but nothing makes the body text appear in the recipients' emails when Mime Mail is enabled.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

awebmanager created an issue. See original summary.

Delphine Lepers’s picture

I am using simplenews with mimemail and i don't have the issue you report.
I have full_html as value for the variable mimemail_format

Mykola Dolynskyi’s picture

@awebmanager just set cron to be called from special URL only
I killed 5 days to track this "empty emails" trouble

FrancescoQ’s picture

I've found the same issue and i think that the cause of this is that mimemail tries to retrieve a plaintext version from html if it's not explicitly setted. The issue is that the module use a preg_match to find the tag, but most of the mails sent (included from the core itself) only include the markup of the text itself, like the

tags and so on.
Attached patch should fix the problem but i actually don't know why they were searching for the tag.

Step to reproduce:

  • Plain D7 installation
  • Enable mimemail
  • Make sure that the user has NOT checked "plaintext email only" in his profile
  • Try to recover passwor
  • Received mail should have content
  • Change the checkbox to force only plaintext emails
  • Try to recover passwor
  • Received mail should be blank

With the attached patch everything works fine for me.

Ludo.R’s picture

Although I don't have the same issue explained in the summary, I do get empty emails when the plaintext option is enabled at user-level.

#4 patch solves the issue for me.

TR’s picture

Status: Active » Closed (duplicate)

This is a duplicate of an issue that was already fixed. See #2883745: Notice: Undefined offset: 0 in mimemail_html_body()

crystaldawn’s picture

Status: Closed (duplicate) » Active

This is NOT a duplicate of that issue from what I can see. I have the same problem and it's certainly not fixed. The problem is that $plain is coming in as TRUE but $plaintext is actually EMPTY. This results in an EMPTY email because it never sees the actual body which is HTML, so it never sends the HTML body portion. Result: Empty email.

This line:
if (empty($plaintext))
needs to change to this:

if (empty($plaintext) && $plain == TRUE)

They are completely unrelated issues but have the SAME symptoms. Please dont close items or mark them as duplicates if you arent able to reproduce the issue yourself.

crystaldawn’s picture

Seems it'll require more than just the simple change, it still needs to run html to text function to send an email that looks presentable. I'll draw up a patch later when I get back from dinner :P

TR’s picture

Status: Active » Postponed (maintainer needs more info)

@crystaldawn: You're using the 7.x-1.x-dev ? And have the exact same error?

Notice: Undefined offset: 0 in mimemail_html_body() (line 383 of /home/mysite/public_html/sites/all/modules/mimemail/mimemail.inc)

crystaldawn’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.55 KB

@TR yes, I am using the dev branch and I have the EXACT same error. It's caused by modules not providing a "body" tag. Attached is a patch to catch these problem childs and fix them. The most common one that I've found is the user_contact module. Feel free to add watchdog entries if you like although personally I dont think it's necessary since not all use cases will need a body tag.

crystaldawn’s picture

Title: Emails completely blank when using Mime Mail as default mail module » Emails completely blank when $body doesnt have a body tag

Updating the title to be more accurate

crystaldawn’s picture

I'll have to retract the dev version statement. I thought I was running dev, but I was not :P I also looked at the patches in the other thread and none of them seemed to address the issue I was looking at. Then I started reading the actual threads and around #14 I found where someone added essentially the same patch I did here........ 3 yrs ago. This is one reason I HATE working on Drupal projects. Nothing ever seems to make it into stable versions. I'd be surprised if it made it into the dev version also. The Drupal sites I've had to work on are usually nothing but patch repositories by the 100s lol.

EDIT: I just checked the dev version, the changes I had to make still would have to have been made. Looks like the patch files that fix the issue were ignored #14 in that other thread, which to me would mean it's not actually fixed. Anyway, it's your project, do what you want with it I suppose, but know that it's still broke :D

TR’s picture

Title: Emails completely blank when $body doesnt have a body tag » Emails completely blank when using Mime Mail as default mail module
Status: Needs review » Closed (duplicate)

It's caused by modules not providing a "body" tag

Yes, that's the exact same problem as in #2883745: Notice: Undefined offset: 0 in mimemail_html_body(), which is exactly why I marked this current issue as a duplicate of #2883745: Notice: Undefined offset: 0 in mimemail_html_body(), because it IS a duplicate. We don't need two separate issues for the same problem. And it's more of a feature request than a bug, because the official way to use this module has always been to provide a complete HTML file for the mail, including head and body and html tags. Just providing some markup without enclosing it in a full page is not what the module expects, although it *would* be nice and more user-friendly to guard against improperly formed HTML (like a missing body tag).

If #2883745: Notice: Undefined offset: 0 in mimemail_html_body() didn't fix it, then please re-open #2883745: Notice: Undefined offset: 0 in mimemail_html_body() - *I* did not have anything to do with that patch other than advocate for a test to be included with the solution (at that time I didn't have maintainer privileges but Mime Mail testing had been failing for 3 years and I had just gone through the effort of getting it fixed). I think #2883745: Notice: Undefined offset: 0 in mimemail_html_body() was meant to change Mime Mail so that Mime Mail wouldn't crash if users left out the body tag, but as I said I didn't have anything to do with that solution so I can't say for sure whether it fixed things. Regardless, all the information and discussion is in that issue, so that's the place to talk about it.

Anyway, it's your project, do what you want with it I suppose, but know that it's still broke :D

No, it's not my project at all, I'm just volunteering my effort to triage the issue queue and port this module to D8/D9 and make improvements so that it works for how I want to use it. These are things that ANYONE can do. I've done it so often that I eventually was given maintainer privileges, but it doesn't require maintainer privileges to help out. I don't use the D7 version of this module, but I am willing to commit patches that are properly formed and documented and have accompanying tests so that I can make sure I'm not breaking any of the ~70,000 sites that are still using the D7 version of this module. Because D7 is near its end-of-life, it's far more important to me not to break the current sites that are using this module without complaint than it is to fix edge cases. The first rule is "do no harm", and if you can show that then I will be comfortable adding new code.

The success of any module in Drupal relies on community contributors and volunteers, so please help out. The best way to do that is to write a test to demonstrate the problem - for example the test should try to send an email without a body tag and it should fail. Then any patch to fix the problem can be automatically evaluated by whether it makes the test pass or not.