Skip to main content
  • Home
  • Work
  • Photography
  • Contact
  • Client Extranet
New Rivers Digital
Home Blogs Eric Weik's blog

Sending Multiple Customized Confirmation Messages with Webform.Module

In:
  • Drupal 6
  • Drupal Recipes
  • Webform.module
2Jul2009

The Webform module for Drupal allows for the creation of customized confirmation e-mail messages to be sent after a user fills out a form. This can be accomplished via some simple pointing and clicking in the "Webform email settings" fieldset when editing the form. However, if you need to send out more than one customized message (say one message to the user, and one message to the site administrators), you'll need to utilize the "Additional Processing" feature of the Webform.

The code below loads values from the submitted form, creates a customized message body, defines a hook_mail() callback to complete the message, and then sends the message via drupal_mail(). This code should be added to the "Additional Processing" area (under the "Webform advanced settings" fieldset).

<?php
// Variables we might need from the form
$submitted_email_address = $form['submitted']['email_address']['#value'];
$submitted_first_name = $form['submitted']['first_name']['#value'];
$submitted_last_name = $form['submitted']['last_name']['#value'];

// Mail setup
$to = $submitted_email_address;
$from = variable_get('site_mail', 'default.address@examplesite.com');

// Use this method to load the confirmation message from the webform itself
//$body = drupal_html_to_text($node->webform['confirmation']);

// Use this method to define a custom confirmation message

$body = "
Dear $submitted_first_name $submitted_last_name,

Thanks for your interest in our site.   Feedback from users is very important to us.

Talk to you soon,
The Web Team
"

;

// Define a hook_mail() callback which drupal_mail() will use to complete the $message structure
function webform_extra_mail($key, &$message, $params) {
 
$message['subject'] = "Thanks for contacting us!";
 
$message['body'] = $params['body'];
}

// Theme and send the message via drupal_mail()
$message = drupal_mail('webform_extra', 'reply', $to, language_default(), array('body' => $body), $from, TRUE);
?>
  • Eric Weik's blog

Comments

#1 Credit Where Credit Is Due

Eric Weik's picture

Submitted by Eric Weik on Thu, 07/02/2009 - 12:08.

I've been using this particular block of code for a while now, but searching around a bit, it probably originally came from this thread on Drupal.org: Sending confirmation email.

  • reply

#2 Confirmation email not sending

Visitor's picture

Submitted by Visitor (not verified) on Mon, 12/07/2009 - 19:09.

Below is the code I have entered. It will send the email to admin that someone has submitted the form, but I cannot get the module to actually send out the confirmation module to the person submitting the form.

Any help would be greatly appreciated!

I am using Drupal 6.
Thanks!

<?php
$email_address
= $form_state['values']['submitted_tree']['email_address'];
$name = $form_state['values']['submitted_tree'['your_name'];

$to = $email_address;
$from = variable_get('site_mail', '');

// Use this method to load the confirmation message from the webform itself
//$body = drupal_html_to_text($node->webform['confirmation']);

// Use this method to define a custom confirmation message

$body = "
Dear $name,

Thanks for your interest in our site.  

Talk to you soon,
The Team
"

;

function

webform_extra_mail($key, &$message, $params) {
 
$message['subject'] = "Thanks for contacting us!";
 
$message['body'] = $params['body'];
}

$message = drupal_mail('webform_extra', 'reply', $to, language_default(), array('body' => $body), $from, TRUE);
?>
  • reply

#3 Try $form or $form_values

Eric Weik's picture

Submitted by Eric Weik on Mon, 12/07/2009 - 20:00.

I'd have to look to be sure, but I think that you might want to use the $form[] array here instead of $form_state[].

So from your example, try replacing your first two lines with:

<?php
$email_address
= $form['submitted']['email_address']['#value'];
$name = $form['values']['your_name']['#value'];
// ... rest of your code here ...
?>

If you have the devel module installed, you can also examine the available variables with something like this:

<?php
dpm
($form);
dpm($form_values);
?>
  • reply

#4 Fixed

Visitor's picture

Submitted by Visitor (not verified) on Tue, 12/08/2009 - 17:36.

Thanks for help, I got it working :-)

  • reply

#5 Thank You!

Steve Kessler's picture

Submitted by Steve Kessler (not verified) on Thu, 01/14/2010 - 14:32.

Your code worked perfectly for my very simple use case.

Thank you very much for supporting the community!

-Steve

  • reply

#6 IS it possible to send confirmation email in HTML format.

Ron's picture

Submitted by Ron (not verified) on Sat, 07/17/2010 - 08:05.

Hello Eric,

I just came across your site when I was searching how to send confirmation email in Webforms.

I am going to try out the way you explained. I was wondering if it is possible in webform to send a confirmation .html format email ?

Also is it possible to add customizations from webform input. Like when a visitor enters his name and company name it should be possible to address him on his name in the email reply ?

I hope I have been able to explain !

Best wishes to you.

Ron

  • reply

#7 HTML version?

Ralph's picture

Submitted by Ralph (not verified) on Mon, 08/16/2010 - 16:20.

I tried a few things with no luck, but is there a way to have the message body use HTML rather than plain text? I'm hoping to add a logo and other graphics...

Thanks

  • reply

#8 Thanks

ServeOthers's picture

Submitted by ServeOthers (not verified) on Mon, 01/31/2011 - 04:33.

Hello,

Thanks for this PHP, It saved me a lot of time.

  • reply

#9 adding images

mm's picture

Submitted by mm (not verified) on Wed, 02/09/2011 - 03:43.

Hi

this works great. But is it possible to add images like company logo at the bottom of the email send to the user.

  • reply

Post new comment

Warning
I strongly encourage and welcome links and feedback. However, this site is moderated and comments with inappropriate links are rejected. Please do not post a one-line "Me too" or "Great post!" comment just so you can link to your site. Thank you for your understanding.
The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Use to create page breaks.

More information about formatting options

Blog Posts (RSS)

About

Hello! My name is Eric Weik. I am a computer scientist, photographer, musician, and occasional blogger. New Rivers Digital is my software consulting business. I am dedicated to using open source software and open data standards for Web development and applications integration. In particular, I am an ardent Drupal fan and specialize in Drupal module development, theming, and data architecture integration.

Contact Details

New Rivers Digital
PO Box 784

Lancaster, VA 22503

Voice+1-804-577-8526
Fax +1-804-462-3229
Contact Form

Content Tags

Abstract B&W Celestial Clouds Drupal 6 Drupal Recipes Drupal Sites Estuary Etsy Government Grasses HDR Long Exposure Macro New Rivers Digital Orton Photoblog Photo Expedition Photoset Renderblog RGB Sketchbook Snow Storm Structure Synth Sunflow Sunset Theming Webform.module Wide Angle Zen Zen Theming
more tags

Recent comments

  • This is stunning
    2 weeks 6 days ago
  • #42 worked well for me
    3 weeks 3 days ago
  • Email by country
    12 weeks 3 days ago
  • hid conversion kit
    13 weeks 3 days ago
  • James
    14 weeks 2 days ago
  • Michelle
    14 weeks 3 days ago

Popular content

Today's:

  • Using Drupal Actions, Triggers, and Tokens to Send Notifications About Comments
  • Implementing Flickr Slideshow Links By Theming Flickr.module
  • Non-Unique Conditional Email Addresses with Webform.Module

All time:

  • Using Drupal Actions, Triggers, and Tokens to Send Notifications About Comments
  • Sending Multiple Customized Confirmation Messages with Webform.Module
  • Non-Unique Conditional Email Addresses with Webform.Module

Activity Stream

  • Sun, 01/29/2012 - 22:31

  • Flickr Eric posted #0228 - Sunset Tree 10:31pm #
  • Flickr Eric posted #0225 - Rappahannock 10:30pm #
  • Flickr Eric posted #5617 - Hobie Sailing 11:56am #
  • Mon, 01/16/2012 - 10:43

  • Flickr Eric posted #5687 - Broken Tree (Digital Sketch) 10:43am #
  • Fri, 01/06/2012 - 07:54

  • Flickr Eric posted #8975 - Greenvale Creek 7:54am #
  • Flickr Eric posted #8824 - Grass (blue ch) 7:46am #
  • Flickr Eric posted #5687 - Broken Tree (IR) 7:35am #
  • Flickr Eric posted #3205 - Toadstool 7:21am #
  • Flickr Eric posted #2318 - Tree and Beach 7:13am #
  • Flickr Eric posted #2251 - Low Tide Arrival 7:04am #
more from my activity-stream


I am a member of the Drupal Association.
Eric At NRD on Drupal.org
Circumjacence (Eric Weik) on Twitter
Circumjacence on Delicious
Eric Weik on Linkedin
Circumjacence (Eric Weik) on Flickr
Circumjacence (Eric Weik) at StumbleUpon

Powered by Drupal & Genesis | Valid XHTML 1.0 Strict | Syndicate content RSS Feed

© 2010 New Rivers Digital | PO Box 784 | Lancaster, Virginia 22503 | +1-804-577-8526 | Contact Form