Having a problem theming or changing the looks of my outgoing contact form e-mails.

I have followed this topic on the subject: How can I theme the outgoing contact mail?

I have done all the points nicholas.alipaz mentions (except 7. since I don't need that). I also have Berdirs code in my .theme and custom module. (yourmodule is of course replaced with the real theme name [is it supposed to be the module name for the custom module or the theme name??])

In .theme file:

* Implements hook_entity_type_alter().
* @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
function yourmodule_entity_type_alter(array &$entity_types) {

* Implements hook_mail_alter().
function yourmodule_mail_alter(&$message) {
    if ($message['module'] == 'contact' && isset($message['params']['contact_message'])) {
// Enforce that we are sending mails as HTML.
    $message['headers']['Content-Type'] = 'text/html';

In custom module:

namespace Drupal\yourmodule;

use Drupal\contact\MessageViewBuilder;
use Drupal\Core\Entity\EntityInterface;

* Customized contact message view that does not do HTML to plain conversion.
class ContactMessageViewBuilder extends MessageViewBuilder {

 * {@inheritdoc}
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
    $build = parent::view($entity, $view_mode, $langcode);
    // Remove the post render callback that converts the HTML to plain text.
    return $build;

I selected one column view via display suite but the only thing that happened was

< data-quickedit-entity-id="contact_message/" class="view-mode-mail ds-1col clearfix"> 

was added to the e-mail after the "user sent message using contact form at" text. The email itself was in plaintext, not HTML.

I really am at a loss here, what to do and I couldn't comment, so I had to make a new topic about the same thing.

  • I have turned off in SwiftMailer this option Respect provided e-mail format (The header "Content-Type", if available, will be respected if you enable this setting. Settings such as e-mail format ("text/plain" or "text/html") and character set may be provided through this header. Unless your site somehow alters e-mails, enabling this setting will result in all e-mails to be sent as plain text as this is the content type Drupal by default will apply to all e-mails. ) and am now receiving HTML emails but the content is still very ugly. Is there a way to get the fields and values?
    – geko
    Jun 6 '16 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.