While searching for mail formating I found alot of questions directed to readme.txt - While the documentation there is quite good I think it could be improved alot via providing theme snippets for all the common tasks and an example template file. "Copy and paste coding" is probably not optimal but it helps getting people quickstarted and reduces redundant questions in the issue quere.

If anyone who has finished an email template stumbles across this issue would copy, generalize and comment some of his code we might be able to get such a list together quickly.

Comments

mlaw’s picture

Here's my template for one of my Webform emails. It's pretty straight forward.

<?php
	// Load all the form values from the submitted webform
    $v = $form_values['submitted_tree'];
        
    // Start of custom email
	print 'Request Product License Key for '. $v['operating_system'] .' by '. $v['full_name'] .' as follows:' ."\n";
    print ' ' ."\n";
	print '------------------------------------------------------------' ."\n";
	print 'CONTACT INFORMATION' ."\n";
	print '------------------------------------------------------------' ."\n";
	print 'Name:             '. $v['full_name'] ."\n";
	print 'Occupation        '. $v['occupation'] ."\n";
	print 'Company:          '. $v['company'] ."\n";
	print 'Address:          '. $v['address'] ."\n";
	print 'City:             '. $v['city'] ."\n";
	print 'Province/State:   '. $v['provincestate'] ."\n";
	print 'Postal Code:      '. $v['postal_code'] ."\n";
	print 'Country:          '. $v['country'] ."\n";
	print 'Phone Number:     '. $v['phone'] ."\n";
	print 'Fax Number:       '. $v['fax'] ."\n";
	print 'E-mail:           '. $v['email'] ."\n";
    print ' ' ."\n";
	print '------------------------------------------------------------' ."\n";
	print 'PRODUCT LICENSE INFORMATION' ."\n";
	print '------------------------------------------------------------' ."\n";
	print 'OS:               '. $v['operating_system'] ."\n";
	print 'GI License keys:  '. $v['your_license_keys'] ."\n";
	print 'Upgrade to:       '. $v['i_want_to_upgrade_to'] ."\n";
    print ' ' ."\n";
	print '------------------------------------------------------------' ."\n";
	print 'FLOATING LICENSE INFORMATION' ."\n";
	print '------------------------------------------------------------' ."\n";

    // Loads the form values from a fieldset (nested array)
    $w = $form_values['submitted_tree']['floating_license_only'];
    print 'Floating IP:      '. $w['ip_address'] ."\n";
	print 'Server ID:        '. $w['server_machine_id'] ."\n";
?>

<?php   // Sections below print date, username, IP address (Webform defaults)    ?>
<?php print t('Submitted on @date', array('@date' => format_date(time(), 'small'))) ?>

<?php if ($user->uid): ?>
<?php print t(' Submitted by user: @username [@ip_address]', array('@username' => $user->name, '@ip_address' => $ip_address)) ?>
<?php else: ?>
<?php print t(' Submitted by anonymous user: [@ip_address]', array('@ip_address' => $ip_address)) ?>
<?php endif; ?>
jadowd’s picture

Where do you put this code? I have several forms that I need to optimize the email output for.

Thanks,

s.Daniel’s picture

This goes in files in your theme like webform-mail-4769.tpl.php - more information is available in the THEMING.txt supplied with the module.

Thanks alot mlaw for providing this example it will help alot of people. I have just checked my template file but what you have provided is by far more suitable as an example.

jadowd’s picture

Thanks Guys, this has been a great help and an awesome learning experience.

Regards!

xalexas’s picture

Thanks a million for this! I was searching everywhere for this explanation.

THEMING.txt was not very helpful. Consider that everyone doesn't know Drupal in depth. Please write some code for beginners like this one in THEMING.txt.

Simplest form of displaying submited field value for me is something like this:

print $form_values['submitted_tree']['name of your field'];

Maybe this one is better but I don't know how to dynamically print field labels. If anyone know how to print labels please post here.

print "<ul>";
  foreach ($form_values['submitted'] as $key => $value) {   
      print "<li>".$form_values['submitted'][$key]."</li>";  
  }
 print "</ul>";
mlaw’s picture

Glad my theme up top has been helping. Perhaps somebody can help me with a new situation I'm facing:

I have a select component that has a key-value pair of: 45|Canada Express Shipping - $45

I'm trying to only call the value 'Canada Express Shipping - $45' in my Webform theme email using this code:

$form_values['submitted_tree']['shipping'];

However, it only pulls the key which is '45'. How do I only pull the value 'Canada Express Shipping - $45' into my webform themed email?

Thanks

quicksketch’s picture

In 3.x you would simply use the token %email[shipping]. In 2.x, it gets sticky because you have to pull the component out of $node->webform['components'], then parse the list of options and match "45" to the option.

mlaw’s picture

Thanks, quicksketch. I'll settle for another option and wait for this functionality in 3.x. :)

quicksketch’s picture

Status: Active » Closed (fixed)

This is of much less importance now that the 3.x version has a built-in templating system for e-mails.

mlaw’s picture

That's great to know. I've been wanting something like that for a long time.

Perhaps this is the wrong place to post this question but I'll ask anyways: if I upgrade to Webform 3.x, will all my 2.x Webforms be intact and work correctly?