Skip to main content
added 866 characters in body
Source Link
AjitS
  • 10.9k
  • 7
  • 41
  • 73

drupal_mail(), by default sends a mail as plain text.

If you print out the array $message['headers'], you will get something like:

array(
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer' => 'Drupal',
  );

As you can see, the Content-Type in the mail header is text/plain; charset=UTF-8; format=flowed; delsp=yes. You can try by modifying this header in hook_mail_alter(), you could use one of the modules which allows you to send the mail as HTML, like HTML Mail, or Mime Mail.

Edit:

Following the comments by @Ayesh and @alechko and after looking into the APIs, I found out that the headers are not the only reason for sending the mail as plain text. Because drupal_mail() internally makes a call to drupal_mail_system(), which returns an object that implements the MailSystemInterface interface. The format() method implemented by drupal_mail_system() is responsible for stripping out the HTML from the emails. So, even if the headers of the mail show the formats to be HTML, the mails would be sent as plain text only. So, I guess one could not send an HTML mail using drupal_mail(). You should look for some other alternative (module) mentioned above.

drupal_mail(), by default sends a mail as plain text.

If you print out the array $message['headers'], you will get something like:

array(
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer' => 'Drupal',
  );

As you can see, the Content-Type in the mail header is text/plain; charset=UTF-8; format=flowed; delsp=yes. You can try by modifying this header in hook_mail_alter(), you could use one of the modules which allows you to send the mail as HTML, like HTML Mail, or Mime Mail.

drupal_mail(), by default sends a mail as plain text.

If you print out the array $message['headers'], you will get something like:

array(
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer' => 'Drupal',
  );

As you can see, the Content-Type in the mail header is text/plain; charset=UTF-8; format=flowed; delsp=yes. You can try by modifying this header in hook_mail_alter(), you could use one of the modules which allows you to send the mail as HTML, like HTML Mail, or Mime Mail.

Edit:

Following the comments by @Ayesh and @alechko and after looking into the APIs, I found out that the headers are not the only reason for sending the mail as plain text. Because drupal_mail() internally makes a call to drupal_mail_system(), which returns an object that implements the MailSystemInterface interface. The format() method implemented by drupal_mail_system() is responsible for stripping out the HTML from the emails. So, even if the headers of the mail show the formats to be HTML, the mails would be sent as plain text only. So, I guess one could not send an HTML mail using drupal_mail(). You should look for some other alternative (module) mentioned above.

Source Link
AjitS
  • 10.9k
  • 7
  • 41
  • 73

drupal_mail(), by default sends a mail as plain text.

If you print out the array $message['headers'], you will get something like:

array(
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer' => 'Drupal',
  );

As you can see, the Content-Type in the mail header is text/plain; charset=UTF-8; format=flowed; delsp=yes. You can try by modifying this header in hook_mail_alter(), you could use one of the modules which allows you to send the mail as HTML, like HTML Mail, or Mime Mail.