I am trying to send an email with a small html form of hidden fields and a submit button. I have been piecing this together from several very incomplete answers and documentation sources that take several approaches to this but no answer so far has worked for me (so please do not mark this as a duplicate).

I have a module, my_module, and in the my_module.module file I have the following hook.

function ten_sixteen_mail($key, &$message, $params) {
    if (isset($params['subject'])) {
        $message['subject'] = $params['subject'];
    if (isset($params['body'])) {
        $message['body'][] = $params['body'];
    if (isset($params['headers']) && is_array($params['headers'])) {
        $message['headers'] += $params['headers'];

Elsewhere in my_module.module I send an email with the following code. I am getting the email, but without the form and button html, only the


$to = "[email protected]";
$subject = "This is an email subject";
$body = "<p>Here is some text.</p>";
$body .= '<form name="someform" action="https://www.example.com/somepage" method="post">';
$body .= '<input type="hidden" name="somecode" value="' . $somecode . '" />';
$body .= '<input type="hidden" name="something" value="' . $something . '" />';
$body .= '<input type="submit" style="padding: 10px; background-color: #d42c2c; border: 2px solid #cccccc;" value="Click This" />';
$body .= '</form>';
$params = array(
    'headers' => 'Content-type: text/html',
    'subject' => $subject,
    'body' => $body,

$message = drupal_mail("my_module", "my_module", $to, language_default(), $params, "[email protected]");

I have Mail System and Mime Mail installed and enabled.

I'm pretty confused about the config options for both modules. For Mail System I have set the 'theme to render the emails' to my custom theme, though I really don't require any theme-ing of the email it was not an option to disable this.

I have created a new module and key setting with the key my_module for the module my_module.

Mime Mail is set to use the Full HTML Email format.

What am I doing wrong that is preventing my html form from coming through in the email?

  • Have you tried debugging Drupal to confirm that the markup is as you expect when it gets sent? (It gets sent from mimemail_mailengine() in the mimemail.module. Also check the view source option of the email clients you're testing in (test in multiple email clients to be sure) - It's possible that not all email clients support HTML forms.
    – rooby
    Jul 9, 2018 at 23:28
  • It's gmail in chrome which supports it pretty well usually. I checked the source and the html doesn't appear at all. I'll look into debugging. Jul 9, 2018 at 23:33

1 Answer 1


The hook_mail headers need to be like this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.