backdrop-contrib / mimemail

Mime Mail provides functions for other modules to use to send HTML mail.
GNU General Public License v2.0
0 stars 4 forks source link

Mail is sent in plain text without html format and don't attach pdfs. #52

Closed aduhour closed 1 week ago

aduhour commented 1 month ago

Hello, I would like to report that after upgrading my site to php 8.1 (the same with 8.2) the emails are sent in plain text, without html format and do not attach pdf as should be.

The emails mentioned are sent after a webform submission, we hope that the webform results and a pdf formatted with webform2pdf are sent to different recipients.

In contrast, the header of every email is like this:

This is a multi-part message in MIME format.

--02d4aa1fb88ac77caa60940d277f0757223cb8021 Content-Type: multipart/alternative; boundary="6e69f55c1879bdb8b885c6fc1ce960482d8997e30" Content-Transfer-Encoding: 8bit

--6e69f55c1879bdb8b885c6fc1ce960482d8997e30 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit etc.

(email content)

and after the email content, this footer:

--6e69f55c1879bdb8b885c6fc1ce960482d8997e30 Content-Type: text/html; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8Bit

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body id="mimemail-body" class="webform-submission"> <div id="center"> <div id="main"> etc...

And then the PDF is not attached and we have this:

6e69f55c1879bdb8b885c6fc1ce960482d8997e30--

--02d4aa1fb88ac77caa60940d277f0757223cb8021 Content-ID: d0f7e6af63c1022a2f8ab53ac56062fc@mysite.com Content-Type: application/pdf; name="filename.pdf" Content-Disposition: attachment; filename="filename.pdf" Content-Transfer-Encoding: base64

JVBERi0xLjYKJeLjz9MKOCAwIG9iago8PCAvVHlwZSAvUGFnZSAvUGFyZW50IDEgMCBSIC9MYXN0 TW9kaWZpZWQgKEQ6MjAyNDA4MDIxNTEyMDctMDMnMDAnKSAvUmVzb3VyY2VzIDIgMCBSIC9NZWRp etc.

I don't know how to debug this problem, but I'm available to bring any other needed information.

Regards, Andrés

argiepiano commented 1 month ago

Hello Andrés. Is this still a problem? Wondering if this may be a webform2pdf issue. Have you posted an issue there?

argiepiano commented 1 month ago

It would be helpful to know what mail-related modules you have enabled. Do you have mailsystem in conjunction with mimemail? Do you use smtp?

Can you go to Configuration > System > Mail system, and report the configurations you have for Mail System? Same for MIME mail in the same menu.

mazzech commented 1 week ago

Hi @argiepiano

same effect here after upgrading to PHP 8.1. Mail System and MIME modules. Works perfectly when switching back to PHP 7.4. Where do I define the SMTP mode?

argiepiano commented 1 week ago

@mazzech , thanks for this. Can you please go to your active configuration module paste the content for the following files:

argiepiano commented 1 week ago

(SMTP is a separate module that is often used in combination with mailsystem to send emails with smtp protocol)

argiepiano commented 1 week ago

Also, @mazzech, how are you sending these emails? With webform?

mazzech commented 1 week ago

Hi @argiepiano thank you for checking... I use the account mail (e.g. password recovery). As said, this used to work with PHP 7.4

Screenshot 2024-08-31 at 17 18 08 Screenshot 2024-08-31 at 17 22 36 Screenshot 2024-08-31 at 17 19 25

argiepiano commented 1 week ago

@mazzech I'm confused. The Password recovery email IS plain text, not HTML. See admin/config/people/emails

argiepiano commented 1 week ago

OK, never mind. If I add <h1>Test</h1> to the body of the email, it does get interpreted as a HTML tag.

So, I'm trying to reproduce this. I've enabled mimemail, mailsystem and the email is sent correctly in PHP 8.1. There must be another sort of interaction. Can you post here the list of contrib modules you have enabled? Find it at admin/reports/debug

argiepiano commented 1 week ago

Also, could you post here the full "Source" of the email?

argiepiano commented 1 week ago

@mazzech I think I have spotted an issue in the file system.mail.json you pasted.

Can you manually edit that file and add:

"mimemail": "MimeMailSystem",

Just above the "webform" line? Save, clear caches, and try the email again.

EDIT: I can't explain why that line is missing. It may have to do with the order in which you enabled the modules, or with another contrib module that alters system.mail.json.

argiepiano commented 1 week ago

Actually, I don't think what I typed just above is the issue here. I removed that configuration, and the email was still sent correctly as html with PHP 8.1.

argiepiano commented 1 week ago

OK, here's another thought.

I see that MIME mail is configured to use full_html. Could you check admin/config/content/formats to make sure a format with that machine name actually exists? Is your site a D7 upgrade?

Also, check the Recent log messages under Configurations to see if you get any warnings when someone requests a password reset email.

aduhour commented 1 week ago

Hello Andrés. Is this still a problem? Wondering if this may be a webform2pdf issue. Have you posted an issue there?

Hello! I have posted an issue there, yes. Excuse me for the delay. Thank you!

aduhour commented 1 week ago

It would be helpful to know what mail-related modules you have enabled. Do you have mailsystem in conjunction with mimemail? Do you use smtp?

Can you go to Configuration > System > Mail system, and report the configurations you have for Mail System? Same for MIME mail in the same menu.

Hello! I had to disable the mailsystem and mimemail modules the last month to get the emails sent in plain text format. I configured a link to download the pdf. This was my solution to avoid sending mail with mimemail code and no html format.

I've tried to enable the MailSystem and Mimemail modules sequentially today. The problem returns when I configure Mimemail to format emails.

deliv-def-format-mime

I have the same configuration in two other sites I manage with different hosting servers. I have created user accounts to test the email sent as notification. And I also received the mails unformatted, with the issue we are discussing.

I checked the recent log messages and I see messages related to

Webform: Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated en webform_number_format_match() (línea 827 de /(...)/public_html/modules/webform/components/number.inc).

Webform2pdf: Deprecated function: Creation of dynamic property W2PDF::$footer_string is deprecated en W2PDF->setFooterData() (línea 95 de /(...)public_html/modules/webform2pdf/webform2pdf.class.inc).

But when I try the notification email test, I do not see any abnormal messages in the log.

I hope you find this information useful, I remain alert for anything else I can help with.

Regards,

Andrés

argiepiano commented 1 week ago

@aduhour thank you for these additional details.

But when I try the notification email test, I do not see any abnormal messages in the log.

But they are also received in plain text instead of HTML, correct?

Andrés, would you have a moment to visit admin/reports/debug in one of the sites that are experiencing this problem, and paste the information here? Also, it would be helpful if you could paste the content of:

from your active config folder.

My goal is to try to reproduce this problem. So far I have not been able to, with your information and @mazzech's as well. As soon as I can reproduce it, then I can fix it, but it's very hard to fix something I can't see locally.

argiepiano commented 1 week ago

OK, an update: I was able to reproduce the problem with php 8.1 by using a LiteSpeed server in a shared hosting account, but not locally with an Apache server. This still makes it tricky to debug, but at least this is progress. I'm going to look into the delivery code of MimeMail to see if I can see what the problem is.

Any additional info either of you could provide will be helpful.

argiepiano commented 1 week ago

@mazzech and @aduhour: I have found what's causing this!

So, some server (notoriously, Windows ones) use \r\n to separate the email header lines. Others use \n. Backdrop checks for this in the assignment of the constant MAIL_LINE_ENDINGS in mail.inc. Typically this is set to \n both in my local Apache server and in my LiteSpeed shared hosting. However, it looks like LiteSpeed (and possibly others) need \r\n instead of \n - this last one will produce problems with the headers, specifically not being able to recognize the boundaries of the multipart email.

So, at least in my LiteSpeed account, this is solved by editing mimemail.settings.json in your file configurations folder,, and setting mimemail_crlf to \r\n. Then clear caches and try sending emails again.

It would seem like the assignment of MAIL_LINE_ENDINGS needs to be updated to account for other servers that need \r\n?

Please try this and report back.

The content of mimemail.settings.json should be something like:

{
  "_config_name": "mimemail.settings",
  "mimemail_crlf": "\r\n",
  "mimemail_linkonly": 0,
  "mimemail_alter": 0,
  "mimemail_key": "",
  "mimemail_incoming": 0,
  "mimemail_simple_address": 1,
  "mimemail_engine": "mimemail",
  "mimemail_name": "",
  "mimemail_mail": "",
  "mimemail_textonly": 0,
  "mimemail_sitestyle": 0,
  "mimemail_preserve_class": 0,
  "mimemail_format": "full_html"
}
argiepiano commented 1 week ago

(My comment above, however, doesn't quite explain why this worked in 7.4 and not in 8.1. There must be some changes with PHPMailer / sendmail in 8.1).

EDIT: Apparently, since January 2024, sendmail is more strict about using CRLF (i.e. \r\n) as line ends - at least that's what I understood here. This may mean that this module now has to use CRLF in the headers, as opposed to switching back and forth depending on the server.

I'll wait until you confirm this has fixed your problem. Also please report the debug info I mentioned above (specifically, the server you are using).

aduhour commented 1 week ago

Hey! It works! The emails are sent in html format and pdfs attached as expected. Thank you! Andrés

argiepiano commented 1 week ago

Hey! It works! The emails are sent in html format and pdfs attached as expected.

Great! Can you let me know what server you are using? Apache? Windows?

aduhour commented 1 week ago

I tested the solution on two Apache sites. Andrés

aduhour commented 1 week ago

I'll wait until you confirm this has fixed your problem. Also please report the debug info I mentioned above (specifically, the server you are using).

Backdrop CMS: 1.28.2 Installation profile: standard PHP version: 8.2.22 Drupal 7 compatibility: Activado Database server: 10.3.34-MariaDB Web server: Apache jQuery version: 1.12.4 jQuery UI version: 1.13.2 CKEditor 5 Versión: 40.2.0 Used in formats: Filtered HTML, Filtrado seguro

Temas

Default theme: Tatsu (tatsu) Admin theme: Gin (gin) 1.x-3.0.0-beta-4 used when editing or creating content

Enabled modules

Núcleo

admin_bar 1.28.2 block 1.28.2 book 1.28.2 ckeditor5 1.28.2 color 1.28.2 config 1.28.2 contextual 1.28.2 dashboard 1.28.2 date 1.28.2 dblog 1.28.2 email 1.28.2 entity 1.28.2 entityreference 1.28.2 field 1.28.2 field_sql_storage 1.28.2 field_ui 1.28.2 file 1.28.2 filter 1.28.2 image 1.28.2 installer 1.28.2 language 1.28.2 layout 1.28.2 link 1.28.2 list 1.28.2 locale 1.28.2 menu 1.28.2 node 1.28.2 number 1.28.2 options 1.28.2 path 1.28.2 redirect 1.28.2 search 1.28.2 simpletest 1.28.2 syslog 1.28.2 system 1.28.2 taxonomy 1.28.2 telemetry 1.28.2 text 1.28.2 update 1.28.2 user 1.28.2 views 1.28.2 views_ui 1.28.2

Contrib

aggregator 1.x-1.0.1 antibot 1.x-1.2.1 audiofield 1.x-1.2.0 back_to_top 1.x-2.1.3 backup_migrate 1.x-1.0.26 better_exposed_filters 1.x-3.6.2 better_search 1.x-1.1.1 bootstrap_icons 1.x-1.0.0 captcha 1.x-1.7.3 card_recipe 1.x-1.0.1 charts 1.x-1.0.0 charts_google 1.x-1.0.0 charts_highcharts 1.x-1.0.0 civicrm 1.x-5.75.0 civicrm_blocks 1.x-1.0.0-alpha civicrm_cron 1.x-2.0.3 civicrm_member_roles 1.x-5.75.0 civicrm_table_prefixes 1.x-1.0.2 civicrmtheme 1.x-5.75.0 clone 1.x-1.1.4 collapsiblock 1.x-1.0.2 colorbox 1.x-2.17.2 configurable_block_style 1.x-1.0.6 content_access 1.x-1.3.0 content_view_access 1.x-1.0.1 css_editor 1.x-1.1.1 css_injector 1.x-1.11.2 custom_search 1.x-1.0.5 customerror 1.x-1.0.0 entity_plus 1.x-1.0.21 entity_token 1.x-2.0.4 entity_ui 1.x-1.0.2 extlink 1.x-1.18.2 facebook_page 1.x-2.0.0 fanciblock 1.x-1.1.1 faq_recipe 1.x-1.0.8 feeds 1.x-1.1.5 feeds_import 1.x-1.1.5 feeds_ui 1.x-1.1.5 field_group 1.x-1.2.1 field_multiple_limit 1.x-1.0.4 field_visibility_condition 1.x-1.0.0 field_wrappers 1.x-1.1.3 filefield_sources 1.x-1.12.0 flag 1.x-3.6.0 flippy 1.x-1.5.0 font_awesome 1.x-1.5.0 font_awesome_field 1.x-1.5.0 form_wizard 1.x-1.0.0 formblock 1.x-1.0.0 google_fonts 1.x-2.1.3 html5_upload 1.x-1.1.3 image_captcha 1.x-1.7.3 inline_form_errors 1.x-1.0.1 instagram_block 1.x-1.1.2 instagram_feed 1.x-1.0.1 job_scheduler 1.x-1.1.4 jstorage 1.x-1.0.1 libraries 1.x-2.2.3 login_destination 1.x-1.4.1 mailsystem 1.x-3.0.8 matomo 1.x-2.12.3 metatag 1.x-1.22.6 metatag_facebook 1.x-1.22.6 metatag_opengraph 1.x-1.22.6 metatag_twitter_cards 1.x-1.22.6 mimemail 1.x-1.1.6 mini_layouts 1.x-1.0.3 mobile_detect 1.x-1.1.1 nice_menus 1.x-1.0.0 nicemessages 1.x-1.0.3 node_reference 1.x-1.0.3 oembed 1.x-1.0.1 on_the_web 1.x-1.7.3 paragraphs 1.x-1.3.0 paragraphs_bundle_permissions 1.x-1.3.0 paragraphs_jquery_ui_accordion 1.x-1.0.4 passphrase_policy 1.x-1.1.3 pdf_to_image 1.x-1.1.0 pdfjs 1.x-1.1.1 photoswipe 1.x-2.1.3 poll 1.x-1.0.6 publication_date 1.x-2.2.1 r4032login 1.x-1.0.2 recaptcha 1.x-2.2.6 references 1.x-1.0.3 rules 1.x-2.14.2 rules_admin 1.x-2.14.2 scrollreveal 1.x-2.0.2 security_review 1.x-1.3.2 seo_meta 1.x-1.0.16 simplenews 1.x-1.0.8 smart_menu 1.x-1.0.1 splashify 1.x-1.3.4 statistics 1.x-1.0.2 stickynav 1.x-1.0.4 submitted_by 1.x-1.0.2 tcpdf 1.x-6.6.3 title_display 1.x-1.2.2 user_guide_recipe 1.x-1.0.2 user_reference 1.x-1.0.3 video_filter 1.x-3.6.1 views_aggregator 1.x-1.0.6 views_aggregator_more_functions 1.x-1.0.6 views_b_grid 1.x-1.0.0 views_bootstrap 1.x-1.2.3 views_calc 1.x-1.1.1 views_slideshow 1.x-3.3.1 views_slideshow_cycle 1.x-3.3.1 webform 1.x-4.26.3 webform2pdf 1.x-4.2.0 webform_addmore 1.x-2.0.0 webform_autocomplete 1.x-2.2.1 webform_calculator 1.x-2.1.1 webform_civicrm 1.x-5.8.0 webform_submissions_bulk_delete 1.x-1.0.0 webform_validation 1.x-1.16 wordpress_import 1.x-1.0.1 youtube 1.x-1.1.2 youtube_colorbox 1.x-1.1.2

argiepiano commented 1 week ago

@aduhour and @mazzech: I've submitted a PR (#53 ) to fix this issue. Can you please test it?

  1. If you made manual modifications to mimemail.settings.json as above, revert them
  2. Patch the module with the PR
  3. Run update.php
  4. Send a password reset email in PHP 8.1+ and PHP 7.4. Check that the emails are showing correctly

Let me know once you do that.

mazzech commented 1 week ago

Manual fix works, thank you so much:-) I work in a cloud DEV environment and this old site has no patching tools, but I will try on other projects:-)

argiepiano commented 1 week ago

@mazzech would you also test the PR? It's a slightly different approach.

EDIT: oops, I saw your comment about the environment not having patching tools... if you ever find a way to test the PR, please report back here 😉

aduhour commented 1 week ago

Hello @argiepiano, I'm not sure how to test PR on production sites. Do I need to replace the module with the PR? Andrés

argiepiano commented 1 week ago

@aduhour I have merged the PR to allow for easier testing. To test, you need to download the dev version of the module, and replace the one you have (you want to backup your DB before you do so). Then clear caches, and try emailing. After that, be sure to remove the dev version and bring back the current release.

If everything goes well in your testing, I'll create a new release of the module.

aduhour commented 1 week ago

@argiepiano I have tested with the confirmation emails of cancelling an account, and everything is OK. Andrés

argiepiano commented 1 week ago

Thanks @aduhour. I will close this and cut a new release now.