View Full Version : Form sent to email address depending on option chosen
info231367
08-18-2009, 03:01 PM
What's it going to take to set up my contact form with the following option? The recipient of the form needs to match up with the option chosen. For example, if the "service" option is chosen, the form needs to be emailed to the service department's email address. If "sales" is chosen, the form needs to be emailed to the sales department's email address...and so on. Somebody please tell me how this can be done.
Jason Byrnes
08-19-2009, 09:13 AM
Create a select list where the values are the email addresses to send to:
<select name="sendTo">
<option value="sales@domain.com">Sales</option>
<option value="service@domain.com">Service</option>
<option value="support@domain.com">support</option>
</select>
then on the contactus.php page, change line 37:
$RecipientEmail = "".($WAGLOBAL_Contact_Email_To) ."";include("WA_Universal_Email/WAUE_contact_1.php");
to:
$RecipientEmail = "".(isset($_POST['sendTo'])?$_POST['sendTo']:"") ."";include("WA_Universal_Email/WAUE_contact_1.php");
info231367
08-20-2009, 05:54 AM
Thank you for the option value code...it works great. I'd like to take this one step further and add a bcc to each option. Would you please be so kind and give me that code as well?
Jason Byrnes
08-20-2009, 10:23 AM
create another selec t list:
<select name="ccTo">
<option value="sales@domain.com">Sales</option>
<option value="service@domain.com">Service</option>
<option value="support@domain.com">support</option>
</select>
and edit line 30 of the WA_Universal_Email/WAUE_contact_1.php file:
$WA_MailObject = WAUE_AddCC($WA_MailObject,"".($WAGLOBAL_Contact_Email_CC) ."");
to:
$WA_MailObject = WAUE_AddCC($WA_MailObject,"".(isset($_POST['ccTo'])?$_POST['ccTo']:"") ."");
info231367
08-21-2009, 05:15 AM
Thank you for your reply. Unfortunately, the second code you gave me doesn't do what I'm looking for, unless I just don't know what I'm doing. I want to "add a bcc to each option", not add another drop down menu/list in addition to the list I already have. Basically, if the sales department is sent an email because "sales" was chosen in the form, I want that same form to be blind courtesy copied to the general manager without the sales department knowing it was sent. Can this be done?
Jason Byrnes
08-21-2009, 09:53 AM
Does the email need to be cc'd to the same GM email address regardless of which selection is made?
if not, what are the criteria to determine which address it should be sent to?
If it goes to the same address for each selection, just set the $WAGLOBAL_Contact_Email_BCC option in the WA_Globals.
If it goes to a different address, you will need to create an switch case statement like this:
if(isset($_POST['sendTo']) && $_POST['sendTo'] != "") {
switch($_POST['sendTo']) {
case "sales@domain.com":
$WA_MailObject = WAUE_AddBCC($WA_MailObject,"salesGM@domain.com");
break;
case "service@domain.com":
$WA_MailObject = WAUE_AddBCC($WA_MailObject,"serviceGM@domain.com");
break;
case "support@domain.com":
$WA_MailObject = WAUE_AddBCC($WA_MailObject,"supportGM@domain.com");
break;
}
}
just after the following line in the WA_Universal_Email/WAUE_contact_1.php file:
$WA_MailObject = WAUE_AddBCC($WA_MailObject,"".($WAGLOBAL_Contact_Email_BCC) ."");
info231367
08-22-2009, 07:32 AM
Great, thanks! Right now, each email is receiving a subject line that is coming from the WA_Globals file, and all emails have the same subject line. I need each email address to have its own unique subject line. Is this possible? And if so, would you be so kind as to reply with the proper code for this task?
Jason Byrnes
08-24-2009, 02:23 PM
Same sort of switch case logic. in the WA_Universal_Email/WAUE_contact_1.php file, change:
$MailSubject = "".($WAGLOBAL_Contact_Email_Subject) ."";
to:
$MailSubject = "Default Subject";
if(isset($_POST['sendTo']) && $_POST['sendTo'] != "") {
switch($_POST['sendTo']) {
case "sales@domain.com":
$MailSubject = "Sales Subject";
break;
case "service@domain.com":
$MailSubject = "Service Subject";
break;
case "support@domain.com":
$MailSubject = "Support Subject";
break;
}
}
info231367
08-25-2009, 04:13 AM
Thank you for your excellent support. I now have my contact form set up exactly the way I need it.
Jason Byrnes
08-25-2009, 09:00 AM
You're welcome.
Hello. I am interested in your email extension, currently version 4 I think.
I was happy to find this thread as it is exactly what I want to do, have the user choose a department to mail the form to. The only problem is that I do not want the e-mail addresses in the HTML for bots to find like I see here. Can you show me how to avoid that? Looking at another companies product and asking the same question, they suggested a switch solution. For their product they suggested:
In this case create select field:
<select name="email_to">
<option value="department_1">Department 1</option>
<option value="department_2">Department 2</option>
...
</select>
Then in email template use:
To: {#sw(email_to, "department_1,department_2...", "email@address.1,email@address.2...")#}
...
Which is of course using their template system and irrelevant to your extension but i think you can see what I am trying to do.
...actually, looking at this thread, I am confident that this can be done and since it's a holiday I am guessing it might be a while until you respond. Using your money-back guarantee, I may buy your extension and experiment or use the working solution you have here and then modify with your response to me. I am not a coder but can usually see whats going on to copy and paste and get it working. Please post a clear solution. I look forward to getting this working ASAP. :)
Jason Byrnes
04-05-2010, 08:59 AM
In universal email the line that creates the to address is:
$RecipArray[$CurIndex ][] = "me@here.com";
you could modify that to dynamically set a to address based on your select list using:
switch($_POST['email_to']) {
case "department_1":
$RecipArray[$CurIndex ][] = "department_1@here.com";
break;
case "department_2":
$RecipArray[$CurIndex ][] = "department_2@here.com";
break;
default:
$RecipArray[$CurIndex ][] = "department_1@here.com";
break;
}
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.