Forums

Send mail according to check boxes

dkulot 30 May, 2011
Hi!

I need help with sending mail according to selected checkboxes:

My form code:

<div class="form_item">
  <div class="form_element cf_checkbox">
    <label class="cf_label" style="width: 150px;">(*) Please select prefered sailing area:</label>
      <div class="float_left">
         
      <input type="checkbox" name="recipients[]" value="north" id="check00" />North Adriatic<br />
      
	  <input type="checkbox" name="recipients[]" value="middle1" id="check01" />Middle Adriatic (Zadar area)      <br />
      
	  <input type="checkbox" name="recipients[]" value="middle2" id="check02" />Middle Adriatic (Sibenik area)      <br />
      
	  <input type="checkbox" name="recipients[]" value="middle3" id="check03" />Middle Adriatic (Split area)      <br />
      
	  <input type="checkbox" name="recipients[]" value="south" id="check04" />South Adriatic      <br />
      

    </div>


And on submit code:

<?php
$emails_2 = array(
'north'=>'north@email.com',
'middle1'=>'middle1@email.com',
'middle2'=>'middle2@email.com',
'middle3'=>'middle3@email.com',
'south'=>'south@email.com',

$MyForm =& CFChronoForm::getInstance('Send_enquiry2');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?> 


It all works fine, but e-mail are being sent to values of checkboxes (north, middle1...) instead of [email]north@email.com[/email], [email]middle1@email.com[/email]...

here is debug

    Form passed first SPAM check OK
    Form passed the submissions limit (if enabled) OK
    Form passed the Image verification (if enabled) OK
    Form passed the server side validation (if enabled) OK
    $_POST Array: Array ( [Name_Surname] => AAA [State_Country] => AAA[e-mail] => test@mail.com [Phone] => [recipients] => Array ( [0] => north [1] => middle1 [2] => middle2 ) [chrono_verification] => x6hb9 [button_14] => Submit [1d910df29cde412c0fc62634efbbff1e] => 1 [1cf1] => 9ea296f8f2bfccf5a307ef56ce397b03 [chronoformname] => Send_enquiry2 )
    $_FILES Array: Array ( )
    Form passed the plugins step (if enabled) OK
    An email has been SENT successfully from (System)system@mail.com to info@mail.com,north, middle1, middle2
    An email has been SENT successfully from (Admin)admin@mail.com to dkulot@gmail.com
    Debug End


What am i doing wrong?
GreyHead 30 May, 2011
Hi dkulot,

I think you have some typos in your PHP so that bit of code probably isn't working.
<?php
// use this if 'Let ChronoForms Handle Arrays' is set to 'No'
$recipients = JRequest::getVar('recipients', array(), 'post', 'array');

// use this if 'Let ChronoForms Handle Arrays' is set to 'Yes'
//$recipients = JRequest::getString('recipients', '', 'post');
//$recipients = explode(',', $recipients);
 
$emails_2 = array(
  'north'=>'north@email.com',
  'middle1'=>'middle1@email.com',
  'middle2'=>'middle2@email.com',
  'middle3'=>'middle3@email.com',
  'south'=>'south@email.com'
);
$send_to = array();
foreach ( $recipients as $r ) {
  if ( in_array($r, $emails_2) ) {
    $send_to[] = $emails_2[$r];
  }
}
$send_to = implode(',', $send_to); 

$MyForm =& CFChronoForm::getInstance('Send_enquiry2');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $send_to);
?>

Bob
dkulot 31 May, 2011
Hi GreyHead

Well i managed to send mails with this: (ChronoForms handle my posted arrays: NO)

    <?php
    $emails_2 = array(
      'north'=>'1@gmail.com',
      'middle1'=>'2@gmail.com',
      'middle2'=>'3@gmail.com',
      'middle3'=>'4@gmail.com',
      'south'=>'5@gmail.com'
    );
    $recipients = JRequest::getVar('recipients', array('other'), 'post', 'array');
    $to_array = array();
    foreach ( $recipients as $r ) {
      $to_array[] = $emails_2[$r];
    }
    $to_array = implode(',', $to_array);
    $MyFormEmails->setEmailData(1, 'to', $to_array);
    ?>


But have two little problems:


1. On debug after last e-mail is array?? Don't know if that is allright?
An email has been SENT successfully from (System)system@mail.com to 1@gmail.com,2@gmail.com,3@gmail.com,4@gmail.com,Array


2. Is it possible to send e-mail separate or in bcc, so the recipients can't see other recipients mails?


Best regards, Dario
GreyHead 31 May, 2011
Hi dkulot,

Please turn on Form DeBug and copy and paste the results here. It looks as though the from is adding some other results to 'recipients'

You can switch 'to' to 'bcc' and test, you may need to put an address in the 'To Email' field to get it to work though. And we know that CC & BCC don't work with the PHP Mail Function as your mailer.

You can send separate emails - but then you'd need to create the code by hand; ChronoForms can't do this for you.

Bob

PS I'm not sure this does anything useful array('other') unless there is an 'other' => [email]'someone@gmail.com[/email]' in the emails array.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount

{item:title} {images:#}