Hello,

I configured the simplenews module (8.x-1.0-alpha3), Swiftmailer (8.x-1.0-beta2) and the Mailsystem (8.x-4.1) in all possible ways for sending HTML-Mails. And it's working quite fine for a normal newsletter-issue. But if i try to put some html tags in my opt-in/opt-out messages they don't get rendered.
Even my twigs are ignored. Is there some logic or reason behind that? Am i missing something?

Best Regards
FirstSanny

Issue fork simplenews-3003811

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

FirstSanny created an issue. See original summary.

anas_maw’s picture

Having same issue

adamps’s picture

Title: Is there a way to send HTML opt-in Mails? » Add an option to send HTML format opt-in / subscribe mails
Category: Support request » Feature request
Issue tags: -html

1) Need to ensure the email is formatted as HTML
Swiftmailer settings allow you to change for every message the site sends: /admin/config/swiftmailer/messages change the message format to HTML and remove respect provided format.

Can do it smarted in hook_mail something like this

$message['headers']['Content-Type'] = 'text/html; charset=UTF-8';
$message['params']['format'] = 'text/html';

2) Need to ensure the HTML doesn't get stripped or escaped.
At the moment you might get lucky because I think the required escaping is missing - see #3031910: Corruption of subscribe mails that look like HTML.

It would be best to add an option to the module to make it work easily.

adamps’s picture

Version: 8.x-1.0-alpha3 » 8.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new3.98 KB
adamps’s picture

Issue tags: +Plan to commit
adamps’s picture

Version: 8.x-2.x-dev » 3.x-dev
adamps’s picture

StatusFileSize
new4.08 KB

Reroll

nofue’s picture

Using SimpleMail on D9, I cannot switch to any text format other than Plain Text on
/admin/config/swiftmailer/messages

I can set 'content type' to HTML, but the 'HTML Format' option list doesn't even show any other options than 'Plain Text'.

Any hints?

adamps’s picture

Issue tags: -Plan to commit

@nofue Sorry I'm not sure this patch is entirely finished/working yet.

thirstysix’s picture

Component: Usability » Code
Category: Feature request » Support request
Status: Needs review » Needs work
Related issues: +#3031910: Corruption of subscribe mails that look like HTML

Same issue with 3.x-dev with Drupal 9

Problem:

<p>We have received a request for the following subscription changes for <a href="mailto:xxxxxxxxxxxx">xxxxxxx@xxxxxx.com</a> at <a href="http://localhost/xxxxxxxxxxxx/:">http://localhost/xxxxxxxxx/:</a></p>
<p> - &lt;p&gt;Subscribe to Default newsletter&lt;/p&gt;</p>
<p>To confirm please use the link below.</p>
<p><a href="http://localhost/xxxxxxxxxxxxxxxxx">http://localhost/xxxxxxxxxxxxxxxxxxxxxx…</a></p>
thirstysix’s picture

Solution:
Reroll patch as per @AdamPS

Working fine with Drupal 9 version

"drupal/simplenews": "3.x-dev@dev",
......
"patches": {
            "drupal/simplenews" : {
                "HTML format Subscription email fix" : "https://www.drupal.org/files/issues/2021-07-05/simplenews-3003811-html_subscription_email_format_fix-3_x_dev-11.patch"
            }
        },

Go to : /admin/config/services/simplenews/settings/subscription
and change the Text format "Full HTML"

thirstysix’s picture

Status: Needs work » Needs review
thirstysix’s picture

update version hook_update_830005()

adamps’s picture

Status: Needs review » Fixed

Thanks for the patches. Set to "Needs work" as latest patch failed to apply - please can you reroll or fix?

berdir’s picture

Status: Fixed » Needs work

You guess you meant to this "Needs work" ;)

introfini’s picture

In the meantime, others needing to send the email as HTML can use the hook_mail_alter like this:

/**
 * Implements hook_mail_alter().
 */
function MYMODULE_mail_alter(&$message) {
  switch ($message['key']) {
    case 'page_mail':
    case 'page_copy':
    case 'cancel_confirm':
    case 'password_reset':
    case 'register_admin_created':
    case 'register_no_approval_required':
    case 'register_pending_approval':
    case 'register_pending_approval_admin':
    case 'status_activated':
    case 'status_blocked':
    case 'register_confirmation_with_pass':
    case 'status_canceled':
    case 'subscribe':
      $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
      foreach ($message['body'] as $key => $body) {
        $message['body'][$key] = new FormattableMarkup($body, []);
      }
      break;

  }
}
suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new4.19 KB

Re-rolled patch from #13. Please have a look.

adamps’s picture

Category: Support request » Feature request

Thanks I'll take a look as soon as I get a chance

adamps’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Patch is good thanks. Next step this needs tests before commit.

I suggest there should be a new test SimplenewsSubscribeTest::testHtml() something like this.

  1. Enable HTMLTestingMailSystem (see SimplenewsSourceTest::testSendHtml())
  2. Log in as admin user and set confirm_combined_body to contain HTML
  3. Log out and subscribe - the HTML should be escaped
  4. Log in as admin user and set text_format to basic_html
  5. Log out and subscribe - the HTML should be unaltered
adamps’s picture

Issue tags: +Plan to commit
adamps’s picture

Status: Needs work » Postponed
Issue tags: -Plan to commit

Probably won't fix this - instead plan to move simplenews to use Symfony Mailer module.

jaroslav červený’s picture

#17 little edited for work now.

jaroslav červený’s picture

StatusFileSize
new4.75 KB
jocowood’s picture

Rerolled patch for simplenews 3.0.0-beta4

Problem still exists and the provided patch solves it. Please reconsider a fix!

adamps’s picture

Please see #21 - the proposed solution is to use Symfony Mailer, which is now a beta release with 4.5k sites using. Any reason why you can't use it??

Swiftmailer is no longer supported anyway. It doesn't seem to make sense to add features that are only useful in that case. I would like to close this as "won't fix".

sergio.rizo made their first commit to this issue’s fork.

sergio.rizo changed the visibility of the branch 4.x-3003811 to hidden.

sergio.rizo’s picture

I've made a fork and a merge request (!75) thanks to the patch in comment #24. Tested on Drupal 9.5.11, Simplenews version 4.0.0 and also with the Drupal Symfony Mailer module. This patch solved the problem.

sergio.rizo’s picture

Status: Postponed » Needs review
adamps’s picture

Status: Needs review » Postponed

Please see #21 / #25.