if yes how can i do that?
i find mime email module that make available html email for drupal modules.
how we can use this with webform and how can i theme webform output?


cjokomay’s picture

just add this code to your template.php file in your theme directory:

function phptemplate_webform_mail_headers($form_values, $node, $sid, $cid) {
  $headers = array(
    'Content-Type'  => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'X-Mailer'      => 'Drupal Webform (PHP/'. phpversion() .')',
  return $headers;

this is the theme_webform_mail_headers from the webform.module file. all i did was change the content-type from "text/plain" to "text/html". works like a charm...hope that helps!

whitingx’s picture

Can this code be targeted to only send certain webforms as HTML ?

function phptemplate_webform_mail_headers_[NID-HERE]($form_values, $node, $sid, $cid) {
  $headers = array(
    'Content-Type'  => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'X-Mailer'      => 'Drupal Webform (PHP/'. phpversion() .')',
  return $headers;

function phptemplate_webform_mail_message_[NID-HERE]($form_values, $node, $sid, $cid) {
  return _phptemplate_callback('webform-mail-[NID-HERE]', array('form_values' => $form_values, 'node' => $node, 'sid' => $sid, 'cid' => $cid));

edit - just tested and the above code does seem to work :)

ChristianP’s picture

How can I fix so I can use "åäö"? I tried changing the UTF-8 to ISO-8859-1 instead but to no success.

ltam’s picture

When I try this in my template.php, I get the error

Parse error: syntax error, unexpected '[', expecting '(' in ...template.php on line (where the function is)

So it seems it's disliking that I'm trying to specify the nid - did this not cause any problems for you?

Azolia’s picture

You just have to delete [ and ].
For example, if your node id is 6, the code should be :

kuldeep1984’s picture

i have used this code for my particular webform.everything is working fine but after using this now mail is going in spam folder.
Any Solution!!!!!

dylanrao’s picture

I'm using your snippet here in my template.php to send a webform submission as HTML email. It is working for me but I get warning: Missing argument 4 for phptemplate_webform_mail_headers_3() in /home/hcssgb/public_html/sites/all/themes/at_hcss/template.php on line 179. when I submit a webform.

line 179 is function phptemplate_webform_mail_headers_[NID-HERE]($form_values, $node, $sid, $cid) {
Any idea on how I could clear this?

Zoologico’s picture

What if your theme doesn't have a template.php file?

Ogredude’s picture

Then just create one and put that function in it.

smilterman’s picture

Hi everybody,

I've been working on the e-mail formatting for a while now and everything is coming into place.
Only problem is that the links I receive in my e-mail aren't clickable after adding the code in my template.php file
I added as suggested, the following:

function phptemplate_webform_mail_headers($form_values, $node, $sid, $cid) {
$headers = array(
'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')',
return $headers;

Any ideas on how to get the links, for example; "the result can be viewed at..." or "links of images" clickable?

Thnx in advance.

adx’s picture

This is great, thank you. However I get this error on the confirmation page after submission:

    * warning: Missing argument 4 for phptemplate_webform_mail_headers() in /home/spiller/public_html/sites/all/themes/Spiller/template.php on line 92.
    * warning: Missing argument 4 for phptemplate_webform_mail_headers() in /home/spiller/public_html/sites/all/themes/Spiller/template.php on line 92.

It still submits and works fine, but an error obviously shows to people which I'd prefer it didn't...

Anyone have a clue as to why this could be happening?

jeffreyvddb’s picture

I've got the same issue... Did you already find a solution for this problem?

ChristianP’s picture

If it works fine, why not just hide the errors for the public with css?

kustolovic’s picture

I think you are using Drupal 7 and d7 version of webform.

Now all theme functions only receive one variable, an associative array

So it is:


function MYTHEME_webform_mail_headers($variables) {
  $headers = array(
    'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')',
  return $headers;
kennyacock’s picture

I added this function, and it looks like I am getting html, but there are no line breaks. Here is what the output looks like:

Submitted on Sat, 06/11/2011 - 08:47 Submitted by user: Kenny Acock Submitted values are: *1. Match the definitions to the appropriate Developmental Domain: ** A) The process of getting to know and value other people in their lives. Learning to share, cooperate, take turns and negotiate with others. B) The feeling people have about themselves, other people in their lives, and the environment in which they live. C) Gradual gaining of control of large and small muscles. Acquiring large muscle skills such as sitting, and small muscle skills such as pinching. D) The process of learning to think and to reason. E) Development of daily living skills such as toileting, self feeding, dressing and so forth. F) The process of learning to communicate with others through verbal or other communication means. 1a: cPhysical Development 1b: bEmotional Development 1c: eSelf Help 1d: aSocial Development 1e: dCognitive Development 1f: fSpeech/Language Development 2. Number the stages of development in the order that they occur: 2Age of Exploration 2b: 3Early Elementary 2c: 4Pre-adolescence 2d: 3Preschool 2e: 5Adolescence 2f: 1Age of Dependence 3. All people develop the same way, at the same time.: False 4. The skills developed during the age of dependence are the foundation for all later development.: True 5. In the Adolescence stage, emotions are calm, controllable, and rational.: False 6. Knowing the predictable sequence of behavior helps parents, educators and other professionals to develop individualized programs.: True 7. During the Age of Dependence developmental state, children learn skills necessary for them to (a)_______________, (b)_______________ and (c)_______________ themselves.: (a)feed 7b: (b)cloth 7c: (c)toilet *8. During this phase, children tend to be self centered, but they also need companionship, and need to be able to play with children the same age. Their attention spans are short and they can be easily diverted. They always seem on the go, and learning about their new world. They require a great deal of attention and support from adults. Which phase is this? ** 8a: Preschool Phase *9. During this phase, children tend to experience rapid growth and body changes which are likely to be accompanied by periods of fatigue. It is not uncommon for them to experience feelings of self-consciousness, shyness and insecurity. During this period, their peer group has more influence over them than any other group. Which phase is this? ** 9a: Adolescence *10. During this phase, children have mastered many more skills and language. They will begin jumping off of furniture or riding a bike. Children will spend more time in active play at the beginning of the phase. Children understand longer and more complicated sentences that are said to them. They are using the skills they have learned to finish routines, but they want to continue at their own pace and make the choice of when, and how, to do each routine. Which phase is this? ** 10a: Exploration Phase The results of this submission may be viewed at...

abutze’s picture

If you're using the SMTP module remember to enable 'Allow to send e-mails formated as Html'

brantwynn’s picture

$cid is argument 4 and it may not be necessary? Using Drupal 6.20 and webform 6.3.9 I deleted the $cid argument from the function and it seems to have worked.

so the function I used to drop the error:

function slcomZen_webform_mail_headers($form_values, $node, $sid) {
  $headers = array(
    'Content-Type'  => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'X-Mailer'      => 'Drupal Webform (PHP/'. phpversion() .')',
  return $headers;
Rainman’s picture

with webform 6.3 the function has changed to:

function MYTHEME_webform_mail_headers($node, $submission, $email) {
  $headers = array(
    'Content-Type'  => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'X-Mailer' => 'Drupal Webform (PHP/' . phpversion() . ')',
  return $headers;

although not necessary now with HTML format available within webform 6.3, it could still be used to override text format

Draco’s picture

And where can I get variables in $form_values like $form_values['submitted_tree'] or $form_values['details']

Draco’s picture

I looked this in $_POST array

axroth’s picture

Its working with 6.22 and webform 6.x-3.11. After clearing cache just edit your e-mail and put code in <body>your code, inclunding Tokens </body>

hessam61’s picture

I tried to send HTML emails with the method mentioned above with no luck. You can force webform module to send HTML emails by installing mimemail, and mailsystem modules. They'll add a checkbox to support HTML below email template field in webform. Very easy integration.

Nitad’s picture

Well I am trying to use Mime Mail and I am getting code in the body. Here is more information.


jaroslaw.kaminski’s picture

'X-Mailer'      => 'Drupal Webform (PHP/'. phpversion() .')',

phpversion() WOT WOT WOT?! maybe we should put there our admin password...?

Ayesh’s picture

What's the big deal with php version? See "should I remove CHANGELOG.txt" conversations here.

// Ayesh

hazmoid’s picture

I'm using Bartik-Plus as my theme (allows for drop down menus), and had added the code above to get the HTML formatting working. I was then getting a whole heap of missing attribute errors and wondering why. Found out that the code here applies to webform 6.x and not 7.x
When I looked at the template.php for the Bartik theme, I found the code that was causing the error. I checked the Bartik-Plus theme and found that it already had the formatting for the HTML mail built in. When I remarked out the 6.x code, the emails worked perfectly. Thanks for helping me to find this error. :)

Soul Reaver’s picture

Just to confirm what hazmoid has said... Drupal 7 is slightly different, unless your theme has already done this for you....

My theme wasn't automatically set-up for HTML and I didn't want the bulk of the extra modules just to change a few lines of code, so here's the solution I used...

function MYTHEMENAME_webform_mail_headers($variables) {
	$headers = array(
		'Content-Type'  => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
		'X-Mailer'      => 'Drupal Webform (PHP/'. phpversion() .')',
	return $headers;

You'll notice that I've used MYTHEMENAME (which should be changed to the name of your theme) instead of phptemplate and also the only value passed into the function is $variables rather than $form_values, $node, $sid, $cid....

Hopefully anyone using D7 will find this useful...

kinghfb’s picture

Just confirming that this fix did work for me (D7.x)

Also, a note that this obviously applies to all Webform headers (not a problem in my case, but definitely something to watch for)

Ayesh’s picture

See Webform module folder's THEME.txt file there was a template suggestions to set headers per Webform (node ID) if I can remember.

// Ayesh

taggartj’s picture

Don't do this but in a pinch ...
go to the "thank you page " where you go to after you submit the form where you can see in the url yoursite.com/thankyoupageurl?sid=1234
the ?sid get var
then make your site have php input filter ...change the thank you page to php format (WARNING !!!)
then ...
you will need the component id for name and email found in the webform when you click edit on a feild component eg node/NODEID/webform/components/CID

 // get subid  ...this totally blows but works 
 $sid = $_GET['sid'];
 $sqlname = "SELECT * FROM `webform_submitted_data` WHERE `sid` = '$sid' AND `nid` ='THENODEID' AND `cid`='CID OF NAME INPUT'";
 $q1 = db_query($sqlname);
 $row = db_fetch_array($q1);
 $nameofguy = $row['data'];
 // could use select `data` and db_results(); 

 $sqlemail = "SELECT * FROM `webform_submitted_data` WHERE `sid` = '$sid' AND `nid` ='THENODEID' AND `cid`='CID OF EMAIL INPUT'";
 $q2 = db_query($sqlemail);
 $row2 = db_fetch_array($q2);
 $email_ofguy = $row2['data'];
    //change this to your email.
    $to = "'".$nameofguy ."' <".$email_ofguy.">";
    $from = "'YORENAME' <YOUR@EMAIL>";
    $subject = "MY SUBJECT";

    //begin of HTML message
    $message = '<html>
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {

   //end of message

    // To send the HTML mail we need to set the Content-type header.
  	 $headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers  .= "From: " . $from . "\r\nReply-To: " . $from . "";
    //options to send to cc+bcc
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
    // send the email.
    mail($to, $subject, $message, $headers);

Ayesh’s picture

This code seems to do the job... But I'd never do this!

Someone can trigger emails by just loading the thank you page with different sid as many times he wants.

// Ayesh

Ndesign’s picture

This comment thread works great for D7 except for the fact you can set any specific styles on labels..do i need to open a new issue or does anyone know a way to add markup to your rendered webform labels.
thank you to everyone for your help already.

DeNelo’s picture

EDIT: Scratch this. The issue is Drupal.