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

Sending Multiple Customized Confirmation Messages with Webform.Module

In:
  • Drupal
  • 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!

Visitor'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

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, 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 Bookmarklet Celestial Clouds CSA Date Drupal Drupal Recipes Drupal Sites Dynamic Range Estuary Government Grasses Long Exposure Macro New Rivers Digital Photoblog Photoset RGB Sketchbook Snow Storm Sumi-e Sunset Surf Theming Trigger.module Views.module Webform.module Zen Zen Theming
more tags

Recent comments

  • 3.x Beta
    8 weeks 2 days ago
  • Some feedback from Webform 3.x
    8 weeks 3 days ago
  • rainbow art
    8 weeks 3 days ago
  • Sumi
    10 weeks 5 days ago
  • Thanks for this info! I lost
    11 weeks 4 days ago
  • Look into "Comment Notify"
    18 weeks 4 days ago

Popular content

Today's:

  • Implementing Flickr Slideshow Links By Theming Flickr.module
  • The Meggy Jr. RGB
  • Non-Unique Conditional Email Addresses with Webform.Module

All time:

  • Using Drupal Actions, Triggers, and Tokens to Send Notifications About Comments
  • Implementing Flickr Slideshow Links By Theming Flickr.module
  • Sending Multiple Customized Confirmation Messages with Webform.Module

Activity Stream

  • Thu, 09/09/2010 - 16:24

  • Flickr Eric posted Microcity v2.04.2 (IR sim) 4:24pm #
  • Wed, 09/08/2010 - 13:32

  • Twitter Eric tweeted "@troysomers Mid-September to mid-November is the pinnacle of the year IMHO -- I'm ready!" 1:32pm#
  • Tue, 09/07/2010 - 15:54

  • Twitter Eric tweeted "@troysomers I applaud this idea, even if I won't be able to follow it. Write about what you know and love!" 3:54pm#
  • Twitter Eric tweeted "Well hello again twitter. Long time no see. How about some #photography for the day? http://bit.ly/c6p0XZ" 8:07am#
  • Mon, 09/06/2010 - 21:55

  • Flickr Eric posted DSC04355-foxtails 9:55pm #
  • Flickr Eric posted #04361 - Foxtails 9:54pm #
  • Flickr Eric posted DSC04359-foxtails 9:54pm #
  • Thu, 09/02/2010 - 21:05

  • Del.icio.us Eric linked to The Magic Onions 9:05pm#
  • Sat, 08/28/2010 - 23:00

  • Del.icio.us Eric linked to Fanboy.com 11:00pm#
  • Sat, 08/28/2010 - 22:58

  • Del.icio.us Eric linked to Japanese Emoticons: A Stamp of Success ยป Fanboy.com 10:58pm#
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