Skip to content

Commit 69a3564

Browse files
authored
Merge pull request #262 from itk-dev/feature/html-mails
feature/html mails
2 parents 0c89e21 + 98c343d commit 69a3564

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"drupal/gin_login": "^1.0@RC",
6262
"drupal/gin_toolbar": "^1.0@beta",
6363
"drupal/inline_entity_form": "^1.0@RC",
64+
"drupal/mailsystem": "^4.3",
6465
"drupal/masquerade": "^2.0@beta",
6566
"drupal/message": "^1.2",
6667
"drupal/openid_connect": "^2.0",

composer.lock

Lines changed: 65 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/sync/core.extension.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module:
3434
language: 0
3535
link: 0
3636
locale: 0
37+
mailsystem: 0
3738
media: 0
3839
media_library: 0
3940
menu_link_content: 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
theme: current
2+
defaults:
3+
sender: os2loop_mail_notifications
4+
formatter: os2loop_mail_notifications
5+
_core:
6+
default_config_hash: IhwTepsVwtbtbcT5GzQKhCXDCRvbk3MNkWqPiuiZ10s
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Drupal\os2loop_mail_notifications\Plugin\Mail;
4+
5+
use Drupal\Component\Utility\Html;
6+
use Drupal\Core\Mail\MailInterface;
7+
use Drupal\Core\Mail\Plugin\Mail\PhpMail as PhpMailBase;
8+
9+
/**
10+
* Copy of the default Drupal mail backend, using PHP's native mail() function.
11+
*
12+
* @Mail(
13+
* id = "os2loop_mail_notifications",
14+
* label = @Translation("Custom PHP mailer"),
15+
* description = @Translation("Sends the message as plain text, using PHP's native mail() function.")
16+
* )
17+
*/
18+
class PhpMail extends PhpMailBase implements MailInterface {
19+
20+
/**
21+
* Concatenates and wraps the email body for plain-text mails.
22+
*
23+
* @param array $message
24+
* A message array, as described in hook_mail_alter().
25+
*
26+
* @return array
27+
* The formatted $message.
28+
*/
29+
public function format(array $message) {
30+
$message['body'] = implode(PHP_EOL . PHP_EOL, $message['body']);
31+
$message['body'] = nl2br($message['body']);
32+
$message['body'] = Html::transformRootRelativeUrlsToAbsolute($message['body'], \Drupal::request()->getSchemeAndHttpHost());
33+
34+
return $message;
35+
}
36+
37+
/**
38+
* Sends an email message.
39+
*
40+
* @param array $message
41+
* A message array, as described in hook_mail_alter().
42+
*
43+
* @return bool
44+
* TRUE if the mail was successfully accepted, otherwise FALSE.
45+
*
46+
* @see http://php.net/manual/function.mail.php
47+
* @see \Drupal\Core\Mail\MailManagerInterface::mail()
48+
*/
49+
public function mail(array $message) {
50+
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
51+
return parent::mail($message);
52+
}
53+
54+
}

0 commit comments

Comments
 (0)