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
Comment #1
quicksketchThis 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.
Comment #2
Troy887 commentedIt 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?
Comment #3
quicksketchThis question is out of scope for the Webform issue queue.
Comment #4
trothwell commentedSorry 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:
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.
Comment #5
trothwell commentedComment #6
trothwell commentedI'd like to just share the fix i found for this, i didn't read things correctly but anyway:
Just do this inside the Additional Processing section and it'll overwrite the emails as needed per-domain.
Comment #7
medden commentedI 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
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:
Comment #8
fietserwinSearching 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:
Comment #9
medden commentedThanks Fietserwin,
That does seem to be a much better way to change the value permanently.
Comment #10
tinny commentedfietserwin, using
if ($message['id'] == 'webform_submission')alters the emails for ALL webforms.Is there a way to target a specific webform sending the emails?
Comment #11
trothwell commented@tinny - I think the only way from that hook would be to use arg() to get the nid.
So...
Comment #12
fietserwinYou 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.
Comment #13
raj45 commentedHas 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?