Hi,

Ive got a 6.x drupal site and I need a way to have my webforms fire off confirmation emails to the users who submit them. I found this post that shows a snippet that will make this happen when placed in the "additional Processing" field but it's for 5.x versions. Can someone tell this PHP rookie a snippet that would make my webform fire off a confirmation email to the user?

Thanks a whole bunch!

Comments

quicksketch’s picture

You can easily setup a sort of confirmation simply by using the "Conditional e-mail recipients" feature of Webform. Create an "email" component in which the user enters their email. Then on the main node edit form underneath the normal "E-mail" field, check the box for the email component you created in the Conditional e-mail recipients fieldset. the user will then receive a copy of the e-mail that the administrator received. If you want to change that e-mail, you can follow the theming instructions in THEMING.txt.

vancouverWill’s picture

Yeah I'm having problems with this too. I thought using the "email" type when selecting a new field would work as there is an option to send a confirmation email but that doesn't seem to be working either.

gtothab’s picture

Status: Active » Closed (fixed)

Hey,

Allan D. was kind enough to post this for me in the forums and it made my webform send a confirmation email to users

Here it is:

The function drupal_mail relies in a hook_mail_alter or module_mail for the email body to be set. A quick look into the core hook_mails didn't expose a simple module to choose from, so I've hacked together the following:


$to = $form_values['submitted_tree']['email'];
$params['body'] = "Dear asdf \n\n
Thank you for reserving a table for at our restaurant \n
In case you don't turn up we will call you at \n\n

Kindest regards,\n
Luca Brasi \n
Da Luca, Fish & Seafood Restaurant\n
Bladibla\n
Bladibla\n
Bladibla";

$key = "reservation";
$from = variable_get('site_mail', ini_get('sendmail_from'));
$params['subject'] = "Reservation from";
$params['from'] = $from;
$send = TRUE;
$language =  language_default();
$module= 'none';

  $default_from =

  // Bundle up the variables into a structured array for altering.
  $message = array(
    'id'       => $module .'_'. $key,
    'to'       => $to,
    'from'     => $from,
    'language' => $language,
    'params'   => $params,
    'subject'  => '',
    'body'     => $params['body']
  );

  // Build the default headers
  $headers = array(
    'MIME-Version'              => '1.0',
    'Content-Type'              => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer'                  => 'Drupal'
  );
  $headers['From'] = $headers['Reply-To'] = $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $from;
  $message['headers'] = $headers;

  // Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
  drupal_alter('mail', $message);

  // Concatenate and wrap the e-mail body.
  $message['body'] = is_array($message['body']) ? drupal_wrap_mail(implode("\n\n", $message['body'])) : drupal_wrap_mail($message['body']);

  $message['result'] = drupal_mail_send($message);

  // Log errors
  if (!$message['result']) {
    watchdog('mail', 'Error sending e-mail (from %from to %to).', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_ERROR);
    drupal_set_message(t('Unable to send e-mail. Please contact the site admin, if the problem persists.'), 'error');
  }

The must be an easier way to do this, but it works. I can do tests from work, and they came through with the body intact. :)

If you use one of the HTML mail modules, then there will be a cleaner way of doing this.

Best of luck

Alan

Alan Davison