Forums

[SOLVED]Sending to multiple recipients email address from db

SubCon 26 Dec, 2011
Hello, I'm a new user chronoforms 4RC2.0 joomla 1.5.
I'm trying to send email to multiple recipients by taking their emails from sobi2 items which the user chooses. I made a script which enters the id values of sobi2 items into session. Now what I want is for chronoform to get them id's, get the corresponding email addresses from database (sobi2_fields_data table)
and send them the email.
I did not understand how to work with session data action, so instead I made custom php code and added it to the "On Submit" event. The code gets the emails into 1 variable and separating them by commas. here is the code:

$db =& JFactory::getDBO();
				
$session =& JFactory::getSession();
$cc_ids_arr = JRequest::getVar('sobisend'); //get id's array from session (sobi2 item id's)

$jj=0;
foreach ($cc_ids_arr as $m_id) {
		$query = "SELECT * FROM `#__sobi2_fields_data` WHERE `fieldid` = '7' AND `itemid`='$m_id'";
		$db->setQuery($query);
		$row = $db->loadAssoc();
		if($jj == 0){$comma = "";}else{$comma = ", ";}
		$cc_emails .= $comma.$row['data_txt'];
		//$result = $database->loadObject();
		$jj++;
}

So at this point I don't know how to add those to cc or bcc fields. If I understand correctly I need to add those to the $form object but how? or maybe there is a better way to do all that?

Thanks
GreyHead 27 Dec, 2011
Hi SubCon ,

Add the values to the $form->data array as, for example $form->data['cc_emails'] and the put cc_emails into the Dynamic CC box in the Email setup.

I forget right now whether you need to pass the address list as a string or an array - a quick test should tell you.

Bob
SubCon 27 Dec, 2011
Thank you for the reply, meanwhile I've edited email.php in "administrator\components\com_chronoforms\form_actions\email" and got it to work. the data passed there is comma separated then it explodes it into array of email addresses.
So should I decide to put it back into on_submit event I can $form->data['cc_emails'] there and its not too late for the script to read it, or is it better to pass the addresses earlier somewhere?

thanks
GreyHead 29 Dec, 2011
Hi SubCon ,

The actions are run in sequence so provided that the value is set in a Custom Code action before the Email action it will be OK.

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