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.
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
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
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
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
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
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
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
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
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
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
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
its a comma separated list!
Cheers
Max
<?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.
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
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
please show me your setup emails tab, hide/change any private data
Cheers
Max
echo $MyFormEmails->getEmailData(1, 'to');
make sure this is in the onsubmit before email box
Regards
Max
[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
your debug doesn't show that the form even tried to send emails, you have Enabled : no in the email properties!
Regards,
MAx
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
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
$MyFormEmails->setEmailData(1, 'to', implode(",", $_POST['recipients']));
I'm confused.😟
$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
This code was in my previous attempt.
Reference http://www.chronoengine.com/forums.html?cont=posts&f=5&t=13060&start=15#p32634
The Form Code image shows the code that I added to the On Submit Before section. Am I missing something.
Max
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?
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
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?
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.
Regards,
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
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
That looks OK to me. What do you see in the 'dummy email' after the debug listing?
Bob
$_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
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
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
No. Not that bit either - the block marked (1) in the attached image . . .
Bob
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
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
I also send you an email - did you get it?
Thanks
If you have version 3.1 then please check FAQ31 and use the code shown there for version 3.1.
Bob
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.
/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.
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
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']]);
?>
Hi Inkmoose,
And line 2 of the code in the OnSubmit Before box is ???
Bob
Is this line 2?
$MyForm =& CFChronoForm::getInstance('contact_form');
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]
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
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
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.
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