We require an e-mail to be sent from our own account "webmaster@..." but require the E-Mail "reply-to" to be an e-mail component from the form itself.

I do not see this feature supported currently. Can you guide me and I will help to make a patch to allow this as an option. What must be updated where?

Comments

quicksketch’s picture

I'd suggest you do this in a custom module for all e-mail on your entire site. See the example of hook_mail_alter() I posted in #750690: Form submission EMAIL -> FROM address not taken from email type component (instead, SMTP auth. email is used).

jjchinquist’s picture

I am continuing to comment here because the other issue is closed.

The suggested solution was to use an implementation of hook_mail_alter. The solution is too general due to the fact that the key for all webform submission emails is "webform_submission". My website requires this "Reply-to" specified differently per webform node.

Reading further into the webform hooks, I came accross hook_webform_submission_render_alter.

I will post if I should find anything, but it looks promising due to the comments. Please give suggestions...

/**
 * Alter the display of a Webform submission.
 *
 * This function applies to both e-mails sent by Webform and normal display of
 * submissions when viewing through the adminsitrative interface.
 *
 * @param $renderable
 *   The Webform submission in a renderable array, similar to FormAPI's
 *   structure. This variable must be passed in by-reference. Important
 *   properties of this array include #node, #submission, #email, and #format,
 *   which can be used to find the context of the submission that is being
 *   rendered.
 */
function hook_webform_submission_render_alter(&$renderable) {
  // Remove page breaks from sent e-mails.
  if (isset($renderable['#email'])) {
    foreach (element_children($renderable) as $key) {
      if ($renderable[$key]['#component']['type'] == 'pagebreak') {
        unset($renderable[$key]);
      }
    }
  }
}
quicksketch’s picture

My website requires this "Reply-to" specified differently per webform node.

Ah, sorry I thought you said that "Reply-to" had to be the same across the whole site.

We require an e-mail to be sent from our own account "webmaster@..." but require the E-Mail "reply-to" to be an e-mail component from the form itself.

So doesn't this mean that you could set "Reply-to" based on the user's e-mail entered in the Webform, but then set the "From" to by your webmaster account? I'm missing where a second custom e-mail address would be needed.

Regarding the hook being to general, In 3.x at least, all the necessary information about the webform is now included and accessible from any hook_mail_alter() call, so you can tell the difference between individual forms. See #651042: Please add node id and sid to params in drupal_mail.

Lastly, I don't think hook_webform_submission_render_alter() would do you any good, since you can't modify e-mail headers at that location. You can however theme the e-mail headers in your site's theme, and that can also be done per node. See the THEMING.txt file included with webform or search the issue queue for sending HTML e-mails.

jjchinquist’s picture

After more trial and error, I discovered that hook was not the way to go. I can isolate the webform submission becaue it is a parameter in the hook_mail_alter after all.

/**
 * Implementation of hook_mail_alter() for NID 1307
 */
function webform_email_customizations_mail_alter($message) {
  if($message['id'] == "webform_submission" && $message['params']['node']->nid == 1307){
    //add to the headers array!
   $message['params']['headers']['Reply-To'] = $message['params']['submission']->data[3]['value'][0]; // myaddress@mydomain.com
//    print "<h1>MESSAGE</h1><pre>";
//    //print_r($message);
//    print_r($message['params']['headers']);
//    print "</pre>";
  } 
}

Now the last hurdle to get over is the fact that the 'Reply-To' does not seem to be valid in the params... can anyone tell me what I am doing wrong?!?

jjchinquist’s picture

Version: 6.x-2.9 » 6.x-3.0-beta6

I feel very stupid here because we are already upgraded to 6.x-3.0-beta6. Updating te version for this comment thread.

Maybe this is just a problem then with the translation to German.

I need the headers for this one webform to look like the following
from: kundenservice[at]quax[dot]at
reply-to: [value submitted by user]
to: [value chosen by the user]

The current settings in the Webform Admin API are:
E-Mail-Absenderadresse: Standard
E-Mail-Absendername: Standard

I only see the ability to change the Sender's Address, am I missing something in the API? I do not want the Spam Filter of the person receiving this e-mail from our system to say: "HMMM... this e-mail was sent from IP www.xxx.yyy.zzz, but the sending address is somethirdperson[at]anywhere[dot]com, which does not match with the sending server... I will regard it as SPAM".

jjchinquist’s picture

Being sometimes not willing to give up pays off: For anyone out there requiring theming for Reply-To... this solution works on our server ;) Add the following to your template.php

/**
 * Theme the headers when sending an email from webform.
 *
 * @param $node
 *   The complete node object for the webform.
 * @param $submission
 *   The webform submission of the user.
 * @param $email
 *   If you desire to make different e-mail headers depending on the recipient,
 *   you can check the $email['email'] property to output different content.
 *   This will be the ID of the component that is a conditional e-mail
 *   recipient. For the normal e-mails, it will have the value of 'default'.
 * @return
 *   An array of headers to be used when sending a webform email. If headers
 *   for "From", "To", or "Subject" are set, they will take precedence over
 *   the values set in the webform configuration.
 */
function quax4_webform_mail_headers($node, $submission, $email) {
  $headers = array(
    'X-Mailer' => 'Drupal Webform (PHP/' . phpversion() . ')',
  );
  
  if($node->nid == 1307){
    $headers['Reply-To'] = $submission->data[3]['value'][0];
  }

  return $headers;
}
quicksketch’s picture

Category: feature » support
Status: Active » Fixed

Great, sounds like you figured out a solution through theming.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

fietserwin’s picture

A Drupal 7 version might look like:

/**
 * Theme the headers when sending an email from webform.
 *
 * @param $variables array containing the keys:
 *   node: The complete node object for the webform.
 *   submission: The webform submission of the user.
 *   email: If you desire to make different e-mail headers depending on the recipient,
 *     you can check the $email['email'] property to output different content.
 *     This will be the ID of the component that is a conditional e-mail
 *     recipient. For the normal e-mails, it will have the value of 'default'.
 * @return
 *   An array of headers to be used when sending a webform email. If headers
 *   for "From", "To", or "Subject" are set, they will take precedence over
 *   the values set in the webform configuration.
 */
function basic_webform_mail_headers($variables) {
  $headers = array();

  if(!empty($variables['submission']->data[2]['value'][0])) {
    $headers['Reply-To'] = $variables['submission']->data[2]['value'][0];
  }

  return $headers;
}

notes:
- I don't test on nid (I have several translated versions of a contact form), but directly on the availability of a given field. This works also better for non required e-mail fields.
- empty() won't issue any warning/notice, not if key submission does not exist, nor if it is not an object, nor ...

jamiehollern’s picture

Status: Closed (fixed) » Active

So are there any plans to put this into the module?

quicksketch’s picture

Status: Active » Closed (fixed)

So are there any plans to put this into the module?

No.

sbandyopadhyay’s picture

Status: Closed (fixed) » Closed (won't fix)

Since this won't be included in the webform module, I've created an add-on module to do this: Webform Reply To.

jordanmagnuson’s picture

Title: Reply to in the e-mail » Allow setting Reply-To email header
Version: 6.x-3.0-beta6 » 7.x-4.x-dev
Issue summary: View changes
Status: Closed (won't fix) » Active

Any chance of reconsideration on this? I don't really understand why we can't include a reply-to header option in the webform email settings along with the other options? I need to be able to set the reply-to header in order to get emails sent by webform to work properly with the Mandrill module, and it seems silly to have to use an add-on module just to be able to set that one header (when Webform already allows us to set other headers as expected)...

Put another way: I assume there must be a good reason for not allowing people to set the reply-to header from within the webform settings, but I can't figure out what the reason is...?

quicksketch’s picture

Status: Active » Closed (fixed)

Thanks @JordanMagnuson, I think you're right. Things have changed since that issue was closed, so lets revisit it. To keep the noise level down from this old issue, let's continue this in #2236237: Use Reply-To instead of From e-mail headers (Google/Yahoo/etc anti-spoofing policy marks e-mails as spam).