Email recipient based on drop-down using FAQ31

mrcook 11 Mar, 2009
I know I am making some foolish mistake but I cannot figure out what I am doing wrong. I have tried following the FAQ31 example to set up email recipient based on drop-down selection but it is not working. I have TO: [email]dummy@mydomain.com[/email], subject: testing ecf, from name: ecf inputter, email from: [email]ecf@maclab.com[/email]. I have tried with dynamic TO: but then the TO: field ends up blank. Below is my html, php and posting results:

HTML (simply add DIV around FAQ31 example and put in submit button)
<DIV>
Select the recipient you wish to contact:
<select name="recipients">
  <option value="em1">Name 1</option>
  <option value="em2">Name 2</option>
  <option value="em3">Name 3</option>
</select>
</DIV>
<DIV class=form_item   >
<DIV class="form_element cf_button" ><INPUT  type=submit value=Submit ></DIV>
<DIV class=clear > </DIV></DIV>


PHP (copy and paste from FAQ31)
<?php
$emails = array('em1'=>'name_1@example.com', 'em2'=>'name_2@example.com', 'em3'=>'name_3@example.com', . . .);
$rows[0]->extraemail = $emails[$_POST['recipients']];
?>


Result when submitting with debug on:

_POST: Array ( [recipients] => em2 [2b945da49d6cf3139939248f081c8f13] => 1 )

Any help would be greatly appreciated.
GreyHead 12 Mar, 2009
Hi mrcook,

Sorry, the code needs updating for ChronoForms v3. PLease try
<?php
$emails = array('em1'=>'name_1@example.com', 'em2'=>'name_2@example.com', 'em3'=>'name_3@example.com', . . .);
if ( $emails[0]->to ) {
  $emails[0]->to .= ',';
} else {
  $emails[0]->to = "";
}
$emails[0]->to .= $emails[$_POST['recipients']];
?>
Notes: (a) not tested and may need de-bugging.
(b) If you have more than one email template in the form [0] needs to be changed to match the template, [0], [1], etc. and there is a small bug that needs a code-change to keep the templates in the same sequence.

This should add the new email to any existing 'to' email.

Bob
katart 13 Mar, 2009
I used this updated PHP code and it breaks the sending of any email. I'm not sure what I am doing wrong. I took the PHP code out and everything works fine. Should I add the 'DynamicTo : recipients' field in the Email Setup and the Email Template?

This is the PHP code I added to the OnSubmit - Before sending emailing:

<?php
$emails = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com');
if ( $emails[0]->to ) {
  $emails[0]->to .= ',';
} else {
  $emails[0]->to = "";
}
$emails[0]->to .= $emails[$_POST['recipients']];
?>


please help. Thanks
Max_admin 13 Mar, 2009
Hi,

the $emails variable has been reused😉

you have at least 1 email setup with a TO field which may has any email address ? then add this code to the onsubmit before email:

    <?php
    $emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com');
    $emails[0]->to = $emails_2[$_POST['recipients']];
    ?>


cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 13 Mar, 2009
Great Max! That code worked.

The only thing I noticed was that it replaces the email address of the TO field in the Email Setup. How would I make it ADD to the TO field and not REPLACE what is in the TO field?

Thanks
GreyHead 13 Mar, 2009
Hi katart,

Sorry, I see that they are now an array not a list. This version should work . . . [code removed]

Oops, see Max's post later - I got it wrong.

Bob
Max_admin 13 Mar, 2009
Hi Bob, Katart,

I see that they are now an array not a list



No they are not but I made my code short so its more immune against mistakes, its still a string😉

this one should work ok IF you have another email address in the TO:

        <?php
        $emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com');
        $emails[0]->to .= ','.$emails_2[$_POST['recipients']];
        ?>


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
csifo 28 Apr, 2009
Hi Chrono people😀

I am useing the latest and upto date Chronoforms Component.

I have some questions on why my attempts getting Chronoforms to email depending on a drop down list selection is not working,

does the 'recipients'
$emails[$_POST['recipients']];
have to reflect the drop down list id ?

here is my code at the moment in the 'On Submit code - before sending email:' section...
  <?php
        $emails_2 = array('office1'=>'email1@email.com', 'office2'=>'email2@email.com','office3'=>'email3@email.com');
        $emails[0]->to .= ','.$emails_2[$_POST['office']];
        ?>


And the list code...
<select name="office" id="office">
<option value="office1">office1</option>
<option value="office2">office2</option>
<option value="office3">office3</option>
</select>


When i submit the form the email is sent like normal as if the code was not there.

What i thought should happen is the form generates the default email and sends it like normal, but when someone selects 'office1' it would also email [email]'email1@email.com[/email]' as well as the default email.
Is this how it should work?

Cheers for any help
Csifo
Max_admin 30 Apr, 2009
Hi Csifo,

the code has changed now, here is how it should be:

change:
$emails[0]->to .= ','.$emails_2[$_POST['office']];


to:

$MyForm =& CFChronoForm::getInstance('formname_here');//user form name
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['office']]);


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
biretam 07 May, 2009
Why not just make the email address in the value field and use dynamic to:?
GreyHead 07 May, 2009
Hi biretam,

Mostly because people don't like to include email addresses in the form html where they are open to being scraped and used for spam. The FAQ31 technique makes sure that the addresses are never visible in public.

Bob
katart 08 May, 2009
Will this work for a Checkbox list or Radio Group?
GreyHead 08 May, 2009
Hi katart,

You'd need to modify it a bit but basically - yes.

Bob
katart 08 May, 2009
Let me explain what I am doing and maybe you can lead me in the right direction:

I am creating a form that will ALWAYS be emailed to Email1, but I want the user to have the option to email the form to several other recipients as well. If they select EmailOpt1 and EmailOpt2 from a multiple select list or check box list, the form will be sent to:

Email1
EmailOpt1
EmailOpt2

With the code as it is now, the user can only select one option and that replaces the default option.

Any help would be appreciated! Thanks
GreyHead 08 May, 2009
Hi katart,

I forget exactly what code it take but you can use either an array or a comma separated list in $MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['office']]); I'd try a list first and if that doesn't work switch to an array (or you can go code-mining and hunt down the correct answer, it's probably in the libraries/mails.php file).

Bob
Max_admin 10 May, 2009
Hi Bob, Katart,

its a comma separated list!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 11 May, 2009
I guess this is a little over my head. Here is the code I am using OnSubmit:

<?php
$emails_2 = array('em1'=>'email1@domain.com', 'em2'=>'email2@domain.com');
$MyForm =& CFChronoForm::getInstance('myformname');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?> 


Here is the corresponding code in the form:

<select name="recipients" multiple="multiple" class="cf_select">
  <option value="em1">Email1</option>
  <option value="em2">Email2</option>
</select>


The results I get from this script is...

1. If I choose Email2, it replaces my default TO email address in the Email Setup tab and the form is sent to Email2 ONLY.
2. If I choose both Email1 and Email2, the form is sent to Email2 ONLY. Again replacing the default TO email address.

How can I get the form to send to multiple email addresses (Email1, Email2, etc.) without replacing the default TO email address? I would think that if I get this working correctly, it should be no problem to change the Multiple Select box to a row of Check Boxes using the field values em1, em2, etc.

Please help. Thank you.
Max_admin 12 May, 2009
Hi Katart,

first you need to fix the dropdown box code to accept and post multi values:
    <select name="recipients[]" multiple="multiple" class="cf_select">
      <option value="em1">Email1</option>
      <option value="em2">Email2</option>
    </select>


then because your code here is not as the one posted before, you need to do this change to be able to let users multi select emails:



    <?php
    $emails_2 = array('em1'=>'email1@domain.com', 'em2'=>'email2@domain.com');
    $MyForm =& CFChronoForm::getInstance('myformname');
    $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
foreach($_POST['recipients'] as $k => $v){
$_POST['recipients'][$k] = $emails_2[$v];
}

    $MyFormEmails->setEmailData(1, 'to', implode(",", $_POST['recipients']));
    ?> 


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 12 May, 2009
Thanks for the response Max

I'm still getting an error. I've been debugging this new code and the attached image is the information I am seeing. Let me know if this provides any information.

[attachment=0]Picture 1.png[/attachment]

Thanks
Max_admin 14 May, 2009
Hi Katart,

please show me your setup emails tab, hide/change any private data

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 14 May, 2009
Here it is Max

[attachment=0]setup-email.gif[/attachment]

Thanks
Max_admin 15 May, 2009
mmm, please remove the BCC and the dynamic fields and replace them with normal fromemail and from name, and also add this line of code at the bottom of the previous code and retest, tell me what you see after the form is submitted!

echo $MyFormEmails->getEmailData(1, 'to');


make sure this is in the onsubmit before email box

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 15 May, 2009
Here is the new setup:

[attachment=2]katart-setupemail.gif[/attachment]
[attachment=1]katart-formcode.gif[/attachment]
[attachment=0]katart-debug.gif[/attachment]

This new setup did not send an email to anyone. Did I add the code correctly?

Thanks
Max_admin 18 May, 2009
Hi Katart,

your debug doesn't show that the form even tried to send emails, you have Enabled : no in the email properties!

Regards,
MAx
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 18 May, 2009
Sorry about that. It is usually a small mistake that causes all the issues.

This is still not working as it should, but I do think we are getting close. It looks like the "em1" and "em2" are not being sent as email addresses. I'm receiving a Mailer-Daemon notice for the "em1" and "em2" emails.

I have more images:
[attachment=2]setupemail2.gif[/attachment]

[attachment=1]fromcode2.gif[/attachment]

[attachment=0]debug2.gif[/attachment]

Also, this is the header information on the email that I receive:
From: [my@email.com]
Subject: WCPB Prayer Request
Date: May 18, 2009 9:11:54 AM EDT
To: [email]em1@u15306887.onlinehome-server.com[/email], [email]em2@u15306887.onlinehome-server.com[/email]

Let me know what you think. Thanks
Max_admin 19 May, 2009
Hi katart,

Please put this code at the end of the first code and let me know what you see after the form is submitted
    echo $MyFormEmails->getEmailData(1, 'to');


Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 19 May, 2009
I did put that code in the OnSubmit Before section. Should I replace:

$MyFormEmails->setEmailData(1, 'to', implode(",", $_POST['recipients']));


I'm confused.😟
Max_admin 20 May, 2009
no, don't replace, add it after it:


$MyFormEmails->setEmailData(1, 'to', implode(",", $_POST['recipients']));
echo $MyFormEmails->getEmailData(1, 'to');


it will show us the to emails of the form after the change!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 21 May, 2009
oh sorry, I missed that, and you don't see any extra info over the debug messages when the form is submitted ? if everything works fine then you should see a list of the To email addresses of the email!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 21 May, 2009
You might notice that in my previous post It shows the To Emails are em1,em2 (not [email]email1@domain.com[/email],email2@domain.com). Also, look at this email header that I received from these settings:

From: [my@email.com]
Subject: WCPB Prayer Request
Date: May 18, 2009 9:11:54 AM EDT
To: [email]em1@u15306887.onlinehome-server.com[/email], [email]em2@u15306887.onlinehome-server.com[/email]

Look at the To Emails. This gives me a Mailer-Daemon return email. Does this makes any sense?
Max_admin 24 May, 2009
Hi Katart,

The 3rd image here:
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=13060&start=15#p32450

doesn't show the "echo" line output I'm expecting, please show me a screenshot of all what appears after the form is submitted to make sure we are on the same page!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 26 May, 2009
Thanks Max

Here is the debug image with the form settings used.

[attachment=2]debug1.gif[/attachment]
[attachment=1]setupemail1.gif[/attachment]
[attachment=0]formcode1.gif[/attachment]

Are these settings correct?
katart 27 May, 2009
Max

Were you able to find a solution? I can give you access to the admin section to view the settings if you think it would help.
Max_admin 27 May, 2009
Hi katart, ok, send me this through the contact us page please and mention the link to this post!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
katart 29 May, 2009
Max

Thanks for your help. Your modification to the OnSubmit Before code worked great. I modified the final form for multiple check boxes instead of Multiple Selects list.

Here is a sample code for the checkbox list:

<input value="em1" type="checkbox" name="check[]" />
<label for="check1"">Sample 1</label>

<input value="em2" type="checkbox" name="check[]" />
<label for="check2">Sample 2</label>


Here is the sample code for OnSubmit Before:

<?php
  $emails_2 = array('em1'=>'sample1@domain.com', 'em2'=>'sample2@domain.com',...);
    $MyForm =& CFChronoForm::getInstance('form_name');
    $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
    $new_recipients = explode(", ", $_POST['check']);

    foreach($new_recipients as $k => $v){
    $new_recipients[$k] = $emails_2[$v];
    }

  $MyFormEmails->setEmailData(1, 'to', implode(",", $new_recipients));
  //echo $MyFormEmails->getEmailData(1, 'to');
?> 


This code replaces the ToEmail with any or all emails selected on the form. I Added a CCEmail in the Setup Email tab to have a universal email address the form will always be sent to.

I hope this helps. And thanks to Max for your great extension and support.
Max_admin 01 Jun, 2009
Thank you!🙂

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
inkmoose 17 Dec, 2009
I have followed all steps here but it only send it to TO EMAIL in the form.
here is the debug

$_POST Array: Array ( [recipients] => em1 [text_1] => adsfasdf [button_3] => Submit [cdedfde6e5fd31f2f439ce8bd75abccb] => 1 [1cf1] => 2fdeddecc8a182736ed8c132abf13b40 [chronoformname] => contact )


here is my html form
 <option value="em1">Name 1</option>
  <option value="em2">Name 2</option>
  <option value="em3">Name 3</option>
</select></div>
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Name</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="" id="text_1" name="text_1" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_fileupload">
    <label class="cf_label" style="width: 150px;">Upload</label>
    <input class="cf_fileinput cf_inputbox required" title="" size="20" id="file_2" name="file_2" type="file" />
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_3" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>

Here is my on submit before sending
<?php
        $emails_2 = array('em1'=>'example@email.com', 'em2'=>'example@email.com');
        $emails[0]->to .= ','.$emails_2[$_POST['recipients']];
        ?>
What am i missing? Thanks
GreyHead 18 Dec, 2009
Hi inkmoose,

That looks OK to me. What do you see in the 'dummy email' after the debug listing?

Bob
inkmoose 18 Dec, 2009
Hi Bob - here is the debug - pls note, the email is a valid email- i changed it to dummy for demo.

$_POST Array: Array ( [recipients] => em2 [text_1] => john doe[button_3] => Submit [74ac84d1535184d3dd89414851a9a792] => 1 [1cf1] => c358fc35a9fee37720e8875e24b43e46 [chronoformname] => contact )

even if i select name 2 -it sends email to name 1
GreyHead 20 Dec, 2009
Hi inkmoose,

That's the $_POST array again - there should be a full example email on the debug page - that's what I'm looking for please.

Bob
inkmoose 21 Dec, 2009

Hi inkmoose,

That's the $_POST array again - there should be a full example email on the debug page - that's what I'm looking for please.

Bob



Do you mean this
An email has been SENT successfully from (Website)sample@email.com to [email]sampe@email.com[/email]

It shows the email in the TO Email (I only have 1 email in the TO) I selected email 3 but it sends it to the 1 and only email in the TO field in the email) Do I need to have the 3 email in the TO email field? separate them in comma?
Thanks Bob - I really need to solve this
GreyHead 21 Dec, 2009
Hi inkmoose,

No. Not that bit either - the block marked (1) in the attached image . . .

Bob
inkmoose 21 Dec, 2009
$_POST Array: Array ( [recipients] => em2 [text_1] => Ink Moose [button_3] => Submit [27eda3f0531a29103037aae8b768b987] => 1 [1cf1] => 77f267b466d6b3417f2a518477b04dc3 [chronoformname] => contact )
GreyHead 21 Dec, 2009
Hi Inkmoose,

No, that's the Post array again. Here's what I'm looking for (from your email with some addresses changed)

From: Website [client3@my_site.com]
To: [email]antonio@example.com[/email]
CC:
BCC:
Select the recipient you wish to contact: em2 Name Ink Moose Upload 20091221145644_howtoclosehotmail.doc


Submitted by 24.129.47.226

Files:
/home/client3/public_html/components/com_chronocontact/uploads/contact/20091221145644_howtoclosehotmail.doc

Sadly, it doesn't tell us anything new :-(

The code you are using from the FAQ is for ChronoForms 3.0 - is this the version you have installed? That code will not work with CF 3.1 or later.

Bob
inkmoose 21 Dec, 2009
The version is 3.1 RC5.5 - we have multiple licenses.
I also send you an email - did you get it?
inkmoose 21 Dec, 2009
Can you give me the code to use? Do i need the same number of email in the TO EMAIL FIELD?
Thanks
GreyHead 21 Dec, 2009
Hi Inkmoose,

If you have version 3.1 then please check FAQ31 and use the code shown there for version 3.1.

Bob
inkmoose 22 Dec, 2009
Thanks Bob, just have a quick question.
With this--> [email]name_3@example.com[/email] , do i have to use the _ as part of the email? the first 2 email is just -->sample1@email.com

also ---do i need to put the form name with the _ here--->('form_name_here')

last question, do i also put all the emails in the TO Field in the email setup?
Thanks for all your help.
GreyHead 22 Dec, 2009
Hi inkmoose,

No, yes, not sure.

Bob
inkmoose 22 Dec, 2009
Got this error
/public_html/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code

What am i missing? It send it to the only email I have in the TO FIELD IN EMAIL SETUP.
GreyHead 22 Dec, 2009
Hi inkmoose,

That looks like you may have chopped the end off the error message. Anyhow it's reporting a problem with the code in the OnSubmit Before box.

Bob
inkmoose 22 Dec, 2009

Hi inkmoose,

That looks like you may have chopped the end off the error message. Anyhow it's reporting a problem with the code in the OnSubmit Before box.

Bob


You're right here it is again
public_html/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code on line 2
HERE'S MY SUBMIT CODE
<?php
$emails_2 = array('em1'=>'antonio@domain.com', 'em2'=>'john@domain.com', 'em3'=>'jerr@domain.com', . . .);
$MyForm =& CFChronoForm::getInstance('contact_form');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?>
GreyHead 22 Dec, 2009
Hi Inkmoose,

And line 2 of the code in the OnSubmit Before box is ???

Bob
inkmoose 22 Dec, 2009

Hi Inkmoose,

And line 2 of the code in the OnSubmit Before box is ???

Bob


Is this line 2?
$MyForm =& CFChronoForm::getInstance('contact_form');
inkmoose 22 Dec, 2009
Can you give me some answers please or can someone help. I have been trying to get answers for 3 days but all i got from Bob are just more questions and on and off answers.
LIKE NO, YES, NOT SURE?

My version is 3.1 RC5.5

Here is my html code
<div>
Select the recipient you wish to contact:
<select name="recipients">
  <option value="em1">Name 1</option>
  <option value="em2">Name 2</option>
<option value="em2">Name 3</option>
  
</select>
</div>

<div class="form_item">
  <div class="form_element cf_fileupload">
    <label class="cf_label" style="width: 150px;">Upload</label>
    <input class="cf_fileinput cf_inputbox required" title="" size="20" id="file_1" name="file_1" type="file" />
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_2" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>

here is my on submit code
<?php
$emails_2 = array('em1'=>'email1@domain.com', 'em2'=>'email2@domain.com', 'em3'=>'email_3@domain.com', . . .);
$MyForm =& CFChronoForm::getInstance('web_form');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?> 


I have 1 email at the email setup TO Field.
I have also tried email3 without the under score_ --- [email]email3@domain.com[/email]
inkmoose 22 Dec, 2009

Hi,

the $emails variable has been reused😉

you have at least 1 email setup with a TO field which may has any email address ? then add this code to the onsubmit before email:

    <?php
    $emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com');
    $emails[0]->to = $emails_2[$_POST['recipients']];
    ?>


cheers
Max


Hi There,
I used this code but it sends it to the email in the TO email in the email setup not the email2 which i selected in the form when submitted.
<?php
$emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com');
$emails[0]->to = $emails_2[$_POST['recipients']];
?>
----html code---

Select the recipient you wish to contact:
<select name="recipients">
<option value="em1">Name 1</option>
<option value="em2">Name 2</option>
<option value="em3">Name 3</option>
. . .
</select>

Can anyone who fixed this issue help out? thanks
GreyHead 22 Dec, 2009
Hi inkmoose,

Sorry that you don't like my answers to your questions, I have plenty of other things to do and I'm sure that someone else will be along in a while.

In the mean-time please stop and read the posts in this thread and try to make sense of them before you make your next post and go off at another tangent -- or loop back to code that you've already been told won't work with your version of ChronoForms.

The cause of your error message is probably this line
$emails_2 = array('em1'=>'email1@domain.com', 'em2'=>'email2@domain.com', 'em3'=>'email_3@domain.com', . . .);
where the , . . . just indicates that you could add more email addresses into the array. As it is this is not valid PHP.

Bob
inkmoose 22 Dec, 2009

Hi inkmoose,

Sorry that you don't like my answers to your questions, I have plenty of other things to do and I'm sure that someone else will be along in a while.

In the mean-time please stop and read the posts in this thread and try to make sense of them before you make your next post and go off at another tangent -- or loop back to code that you've already been told won't work with your version of ChronoForms.

The cause of your error message is probably this line

$emails_2 = array('em1'=>'email1@domain.com', 'em2'=>'email2@domain.com', 'em3'=>'email_3@domain.com', . . .);
where the , . . . just indicates that you could add more email addresses into the array. As it is this is not valid PHP.

Bob


Now this is a more specific answer - thanks so much - You're the man - it's fixed.
bschneider 08 Feb, 2010
Hello,

I am at my wits end here trying to get this to work. I am using 3.1, just downloaded and installed it last week. Here is what I have done so far:

I've modified the form for the drop down to the value of em1, em2, em3.

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Which Department?</label>
    <select class="cf_inputbox validate-selection" id="select_8" size="1" title=""  name="recipients">
    <option value="">Choose Option</option>
      <option value="em1">Service and Inspections</option>
<option value="em2">Electronic Sales</option>
<option value="em3">Fire Protection Sales</option>
    </select>
      </div>


I've just copied and paste the php code and change line 2:
<?php
$emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com', 'em3'=>'name_3@example.com',);
$MyForm =& CFChronoForm::getInstance('form_name_here');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?>


Now in my email setup I have Dynamic To and I have changed the field from recipients to an actual email address. For the life of me I can't get it to email anything other than recipients or em1.servername.fqdn which of course doesn't work. I've also change the Dynamic To to TO with a real address. The only time it will email is when I have a real address in the TO field.

What the heck am I doing wrong? I've tried modifying the php code with the other sample code giving and nothing is working for me..

Please help.. Thanks in advance.
Bryan
This topic is locked and no more replies can be posted.