Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/html mails #262

Merged
merged 13 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"drupal/gin_login": "^1.0@RC",
"drupal/gin_toolbar": "^1.0@beta",
"drupal/inline_entity_form": "^1.0@RC",
"drupal/mailsystem": "^4.3",
"drupal/masquerade": "^2.0@beta",
"drupal/message": "^1.2",
"drupal/openid_connect": "^2.0",
Expand Down
66 changes: 65 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module:
language: 0
link: 0
locale: 0
mailsystem: 0
media: 0
media_library: 0
menu_link_content: 0
Expand Down
6 changes: 6 additions & 0 deletions config/sync/mailsystem.settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
theme: current
defaults:
sender: os2loop_mail_notifications
formatter: os2loop_mail_notifications
_core:
default_config_hash: IhwTepsVwtbtbcT5GzQKhCXDCRvbk3MNkWqPiuiZ10s
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Drupal\os2loop_mail_notifications\Plugin\Mail;

use Drupal\Component\Utility\Html;
use Drupal\Core\Mail\MailInterface;
use Drupal\Core\Mail\Plugin\Mail\PhpMail as PhpMailBase;

/**
* Copy of the default Drupal mail backend, using PHP's native mail() function.
*
* @Mail(
* id = "os2loop_mail_notifications",
* label = @Translation("Custom PHP mailer"),
* description = @Translation("Sends the message as plain text, using PHP's native mail() function.")
* )
*/
class PhpMail extends PhpMailBase implements MailInterface {

/**
* Concatenates and wraps the email body for plain-text mails.
*
* @param array $message
* A message array, as described in hook_mail_alter().
*
* @return array
* The formatted $message.
*/
public function format(array $message) {
$message['body'] = implode(PHP_EOL . PHP_EOL, $message['body']);
$message['body'] = nl2br($message['body']);
$message['body'] = Html::transformRootRelativeUrlsToAbsolute($message['body'], \Drupal::request()->getSchemeAndHttpHost());

return $message;
}

/**
* Sends an email message.
*
* @param array $message
* A message array, as described in hook_mail_alter().
*
* @return bool
* TRUE if the mail was successfully accepted, otherwise FALSE.
*
* @see http://php.net/manual/function.mail.php
* @see \Drupal\Core\Mail\MailManagerInterface::mail()
*/
public function mail(array $message) {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
return parent::mail($message);
}

}