【问题标题】:Drupal 8, Webform module : send html mail with plain text mime/alternativeDrupal 8,Webform 模块:发送带有纯文本 mime/alternative 的 html 邮件
【发布时间】:2021-09-01 02:57:46
【问题描述】:

我们使用 Webform Drupal 8 模块来处理网站上的时事通讯订阅。将发送一封 html 格式的电子邮件以确认订阅。不幸的是,这封电子邮件仅使用 content-type:text/html 发送,您知道 Spamassassin 对此有多挑剔。这是一个真正的可交付性问题。 我们希望能够使用 content-type:multipart/alternative 发送该电子邮件,其中包含 2 个部分:一个具有 text/html 内容类型,另一个具有 text/plain。 我们应该怎么做 ?我们安装了“邮件系统”和“mime 邮件”模块,但我们不知道如何使用它们,或者即使它是正确的解决方案。 有没有人设法做到这一点?

【问题讨论】:

    标签: html text drupal webforms multipart


    【解决方案1】:

    看看this module

    启用mime-mail module 后,您可以使用hook_mail_alter 钩子(see here) 修改Drupal 发送的电子邮件并添加纯文本版本。

    在自定义模块中,在您的 mymodule.module 文件中,您可以执行以下操作:

    /**
     * Implements hook_mail_alter().
     */
    function mymodule_mail_alter(&$message) {
    
      //to specify which email need altering based on id
      //without this all emails send will be altered
      if (isset($message['id']) && $message['id'] == 'contact_page_mail') {
        
        //set plain text
        $message['params']['plaintext']= "HTML support needed";
      }
    }
    

    【讨论】:

    • 感谢您的回复。我们实现了 hook_mail_alter,即使没有安装 mime-mail 模块,它也能正常工作。我们还必须实现 hook_module_implements_alter 以确保在 webform 之后进行处理。
    猜你喜欢
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-12
    • 2012-12-26
    • 2013-06-10
    • 1970-01-01
    相关资源
    最近更新 更多