Forums

Email Certain user on Select

penny 24 Nov, 2014
In my form I can choose a certain region - AB, BC, SASK, MAN (they are currently set as check boxes) When I choose a region and fill out the form I want that region to get the email. So If I choose AB as my region then the form will get sent to ab@email.com. If I choose AB and BC as my region then the form will get sent to ab@email.com and bc@email.com.
am I able to do this by somehow setting the variables in the "Dynamic" part of the send email event?

Thanks
Penny
penny 04 Dec, 2014
I am just wondering if anyone had a chance to look at this.
Thanks
Penny
GreyHead 04 Dec, 2014
Hi Penny,

This is tricky in CFv4 because I think I'm correct in saying that the standard Email action won't send to a list of addresses using the Dynamic To box. If you get my custom Email [GH] action that should work OK

For the basic code to set this up please see this FAQ

Bob
penny 04 Dec, 2014
Bob,

Thanks for your reply. I installed the action through the Chronoforms action tab and it said that it installed successfully.

The directions that you added are unfortunately not that clear. I am going to assume that I am to use the email [GH] action in the Onsubmit.
These are the setting that I have
[attachment=0]email.jpg[/attachment]
[attachment=1]email1.jpg[/attachment]
penny 04 Dec, 2014
I noticed an error in my PHP code and have fixed it to be the following
<?php
$recipient = JRequest::getString('recipients', 'em1', 'post');
$emails = array (
  'em1' => 'aaa@domain.com',
  'em2' => 'v.bbb@domain.com',
  'em3' => 'b.ccc@domain.com',
  'em4' => 'ddd@domain.com' );
$form->data['email_to_use'] = $emails[$recipient];
?>
GreyHead 06 Dec, 2014
Hi Penny,

I can't see from here what option values you have in the drop-down and you don't seem to have edited the PHP to account for the need to send to more than one email address in some cases?

Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.

Bob
penny 08 Dec, 2014
Bob

I have since changed my select boxes to a "Group Select"

Penny
GreyHead 08 Dec, 2014
Hi Penny,

As you can see in the Debug output the email_to_use variable is empty. This is probably because you've switched to use a multi-select checkbox group but haven't updated the Custom Code to work with the array that this returns - you can see the values that has in the Debug Ouput.

Bob
penny 08 Dec, 2014
Oh dear.. I feel like this is becoming confusing...
So this is my set up.

I have a a group text box
Field Name and Field ID are set to "recipients"
in the options I have
em1=Colombie-Britannique
em2=Alberta
em3=Saskatchewan
em4=Manitoba


On my Events - On Submit (in Order)
Show Thanks Message
Custom Code - Mode is Controller
<?php
$recipient = JRequest::getString('recipients', 'em1', 'post');
$emails = array (
  'em1' => 'email1@email.com',
  'em2' => 'email2@email.com',
  'em3' => 'email3@email.com',
  'em4' => 'email4@email.com' );
$form->data['email_to_use'] = $emails[$recipient];
?>


Email [GH] - Enabled
To Field is - email_to_use 


Check Captcha
Debugger
penny 05 Jan, 2015
Any help on this?

Thanks
Penny
GreyHead 06 Jan, 2015
Hi Penny,

It looks as though you are still using the same PHP - and that is only returning a single email address. You need to update it to return an array or a comma separated list if you want to add more than one To Email address.

Bob
This topic is locked and no more replies can be posted.