I've been searching for a way to choose more than one (two in my case) components values from my webform to set as "E-Mail from name" for a particular webform.

I'm working with separated form-fields for "firstname" and "lastname" for later processing.
So actually I'm only able to select either "firstname" or "lastname" as component in Webform mail settings "E-Mail from name". But I need both. Is there any other option to handle this? I tested to use tokens in the "user defined" field, but this doesn't seems to work. Anybody with an idea?

Comments

asxnot’s picture

I had the same problem.
I solved it by adding a function theme_mail_headers to my template.php.
In the function I added the following line:

  if ((array_key_exists("profile_firstname",$form_values["submitted_tree"]))&&(array_key_exists("profile_lastname",$form_values["submitted_tree"])))  
  {$headers["From"] = '"'.$form_values["submitted_tree"]["profile_firstname"]." ".$form_values["submitted_tree"]["profile_lastname"].'" <'.$form_values["submitted_tree"]["email"].'>';}

Hope to be helpful.

mlaw’s picture

I'm facing this issue as well.

what are your calling in the function theme_mail_headers line? Can you post the snippet?

Thanks.

wildebeest’s picture

@asxnot

Could you please explain your solution a little further please?
I'm still searching for a solution..

Thanks in advance!

asxnot’s picture

I used the theming functions provided by webform module.

Pay attention: In the following, the string {templatename} must be replaced by the name of your template

First of all I added two fields (profile_firstname and profile_lastname) to my webfom.

Then, I added the following lines to the function {templatename}_theme in template.php:

function {templatename}_theme() {
  return array(
    [...]
	'webform_mail_headers' => array(
      'arguments' => array('form_values' => NULL, 'node' => NULL, 'sid' => NULL, 'cid' => NULL),
      'function' => '{templatename}_webform_mail_headers'),
    [...]
}

Finally, I added the following function , named {templatename}_webform_mail_headers, to template.php. It overrides the standard theme_webform_mail_headers that is included in the module webform.

function {templatename}_webform_mail_headers($form_values, $node, $sid, $cid) {
  if ((array_key_exists("profile_firstname",$form_values["submitted_tree"]))&&(array_key_exists("profile_lastname",$form_values["submitted_tree"])))  
  {$headers["From"] = '"'.$form_values["submitted_tree"]["profile_firstname"]." ".$form_values["submitted_tree"]["profile_lastname"].'" <'.$form_values["submitted_tree"]["email"].'>';}  
  return $headers;
}

In this way, in all the webforms that include the fields profile_firstname and profile_lastname, these fields will be used as the sender of the message.

quicksketch’s picture

Status: Active » Closed (duplicate)