I am using "Domain Access" on my drupal portal to offer two different websites based on one drupal installation (some content is shared).

The webform – forms are shared => accessible by domain1.com and domain2.com

Is there an easy way to automatically change the webform "E-mail to address" and "E-mail subject" based on the current domain?

Example:
- The user sending a webform is on domain1.com -> "E-mail to address" is info@domain1.com and "E-mail subject" is "Domain1: New Event"
- The user sending a webform is on domain2.com -> "E-mail to address" is info@domain2.com and "E-mail subject" is "Domain2: New Event"

Some more information:
- I am using webform 2.9 at the moment but am willing to update to 3 if this helps somehow
- Simply using a new webform on my second domain would work, but I would have to change lots of pages with links to the old address. So it would perhaps be easier to keep using the old webform and making some changes to it.

Comments

quicksketch’s picture

This should be possible if Domain Access module provides Drupal variables per-domain. Webform simply does a variable_get('site_mail', '') when it sends the e-mails, if Domain Access is capable of providing variables based on your current domain, Webform will automatically use that variable when sending e-mails. I haven't ever used Domain Access myself, so I'm not sure if it provides that functionality or not.

Troy887’s picture

It seems "Domain Access" is indeed changing the variables per-domain.

I create a new webform and on the edit page I can see the default values of "E-mail from name" ( = name of site) and "E-mail from address" ( = site e-mail) changing when calling it with domain1.com or domain2.com. This seems to work well.

But at the moment I can not see how this could help me with the E-mail TO address:
There is only an empty field to enter one or more e-mail addresses, and the Conditional e-mail recipients area.

Is there a way how I can use the E-mail from address default value in the E-mail TO address – field?

quicksketch’s picture

Status: Active » Closed (won't fix)

This question is out of scope for the Webform issue queue.

trothwell’s picture

Status: Active » Closed (won't fix)

Sorry to bring this up but I was attempting to re-use a contact form for a few domains but of course each "E-mail to address:" doesn't seem to pivot.

I tried some dirty alterations within Additional Processing to:

<?php
$form['#parameters'][2]->webform['email'] = 'testing@test.com';
?>

But i had no luck, it just sticks with the one entered within the E-mail to Address field. I'm making the assumption that it ignores the data within $form? Is this a bug or am I just purely not able to alter to this extent?

Any feedback is appreciated, Cheers.

trothwell’s picture

Status: Closed (won't fix) » Active
trothwell’s picture

I'd like to just share the fix i found for this, i didn't read things correctly but anyway:

<?php
$current_site = variable_get('site_name', 'Drupal');

switch($current_site) {
	case 'Example Domain':
		$node->webform['email'] = 'example@test.com.au';
		break;
	case 'Example Domain 2':
		$node->webform['email'] = 'example+2@test.com.au';
		break;
	default:
		$node->webform['email'] = 'example+3@test.com.au';
		break;
}
?>

Just do this inside the Additional Processing section and it'll overwrite the emails as needed per-domain.

medden’s picture

Version: 6.x-2.9 » 7.x-3.x-dev

I figured out how to get this working with the 7.x-3 version of Webform.
Create your own custom module called mymod

add this code

**
* Modify a Webform submission, prior to saving it in the database.
*
* @param $node
*   The Webform node on which this submission was made.
* @param $submission
*   The Webform submission that is about to be saved to the database.
*/
function mymod_webform_submission_presave($node, $submission) {
    // Update some component's value before it is saved.
    $email_from = $node->webform['emails']['1']['from_address'];
    $node->webform['emails']['1']['email'] = $email_from;
}

This will replace the TO email field, with the forms FROM field, which can be set to the default site email, which is Domain Access sensitive.

You may be able to get other domain access variables using the string:

global $_domain;
print_r ($_domain);
fietserwin’s picture

Searching for a way to change the 'to' address of a webform based mail, I found this issue and successfully used the code outline in #7. However, if you go to the submissions page and use the 'resend e-mails' button, that code does not execute anymore (and changes in the email parameters are not saved in the submission data). So I looked for a general way of changing (webform based) e-mails before they are being sent and came up with the following piece of code:

/**
 * Implements hook_mail_alter
 * @see http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_mail_alter/7
 *
 * @param array $message
 */
function mymodule_mail_alter(&$message) {
  if ($message['id'] == 'webform_submission') {
    if (isset($message['params']['node']) && isset($message['params']['submission'])) {
      $node = $message['params']['node'];
      $submission = $message['params']['submission'];
      // do your work, e.g. changing $message['from'], $message['to'], etc.
      ...
    }
  }
}
medden’s picture

Thanks Fietserwin,

That does seem to be a much better way to change the value permanently.

tinny’s picture

fietserwin, using if ($message['id'] == 'webform_submission') alters the emails for ALL webforms.

Is there a way to target a specific webform sending the emails?

trothwell’s picture

@tinny - I think the only way from that hook would be to use arg() to get the nid.

So...

if ($message['id'] == 'webform_submission' && arg(1) == '20') {
//do stuff
}
fietserwin’s picture

You don't have to use arg(). By inspecting the message params, you can retrieve the node and the submission data, giving you about all information you can wish. My example already showed how to get this information. After you have retrieved this information, you are at the same point as in the webform_submission_presave hook. Thus any further narrowing down to specific mails/nodes/situations is done exactly the same as in that hook.

raj45’s picture

Issue summary: View changes

Has anybody tried combining the Domain module with the Webform module, and use a single webform for multiple domains, where the submission is sent to the web site the user sent the message from?