Forums

Sending multiple, conditional, emails + a general one

rstinghe 21 Feb, 2011
Hi,

I have been trying to create a form that sends two emails - one to the same address every time (mine, [email]myemail@example.com[/email]) and another to an address depending on one of the fields chosen by the user.
To do this I have set my address in the general email setup of the form and tried to use some code for sending the "conditional" one.
So, I have put in the "form HTML"
<option value="em1">Email1</option>
<option value="em2">Email2</option>
<option value="em3">Email3</option>


and in the "on Submit code"
<?php
$emails_2 = array('em1'=>'email1@example.com', 'em2'=>'email2@example.com', 'em3'=>'email3@example.com');
$MyForm =& CFChronoForm::getInstance('LoA_appl_2011');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['NSO']]);
?> 


(the names of the fields and the emails have been changed for the purpose of this post).

Now, the problem is that, when someone is filling the form, the email is sent to [email]email1@example.com[/email] but not to my email (the one set in the general email setup). I tried even having an array within an array (e.g.
$emails_2 = array('em1'=>array('email1@example.com', myemail@example.com), 'em2'=>'email2@example.com', 'em3'=>'email3@example.com');
) but with no avail: it gives the user an error and the form is send to [email]myemail@example.com[/email] but not to [email]email1@example.com[/email]!

I assume that there is a simple solution to this but I was unable to find it (and, believe me, I did try searching in the tutorials and perusing all the forums).

Any suggestion will be appreciated,

Thanks for all your work,

radu
GreyHead 21 Feb, 2011
Hi radu,

Please turn debug on in the form General Tab, then submit the form and post the debug - including the 'dummy emails' results here.

Please also post a screenshot of the Email setups you are using.

Bob

PS FYI the 1 in $MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['NSO']]); identifies the Email Setup, its' possible that you are setting this for the wrong Setup.
rstinghe 21 Feb, 2011
Hi,
Thanks for the quick answer. And please remember to talk basic English to me because 1. English is not even my third language and 2. I am an absolute beginner in anything which goes beyond a nice GUI....
That being said here's the debug result:

1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [NSO] => BSA [Troop] => testCF [Patrol] => testCF [Number] => 7 [PL] => testCF [Members] => testCF [Leader] => testCF [Email] => testCF [Address] => testCF [LoA_element] => Express_EURSelf [Express_EURSelf] => testCF [EUR_Door] => Latvia [Notes] => testCF [button_19] => Submit [2bdfb77ff42050b3b12e3c2e957c3154] => 1 [1cf1] => 8a4de87715c439833c23e0c8fadc2f1e [chronoformname] => LoA_appl_2011 )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. An email has been SENT successfully from (LoA Admin)myotheremail@example.com to [email]email1@example.com[/email]
9. Debug End


and the screenshot of the email setup.
[attachment=0]screenshot.jpg[/attachment]

Hope this is what you were asking for in order to work your magic :-)

Radu
GreyHead 21 Feb, 2011
Hi Radu,

Please ask if I say anything that isn't clear to you.

To send two different emails you need two different Email Setups. Please add a second one for the second email.

Bob
rstinghe 21 Feb, 2011
And what do I put into the "To" field? As I have a series of email addresses from which the form "must choose" depending on the user's selection.
rstinghe 23 Feb, 2011
Any help for the question above?
Pleeeeeease! 🤨
Thanks a lot...

Radu
GreyHead 24 Feb, 2011
Hi Radu,

You have the code earlier in this thread for using a Dynamic To to set the email from the value of a drop-down (or radio buttons).

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