[SOLVED] Need to email several people when a form is submitted

escv

New Member
I have a form that needs to generate an email to several people based on what the user selects.

I have a table of contacts with name and email address that is pulled using a database join and displays in a multi select box on the form.
Screen Shot 2017-04-05 at 9.40.01 AM.png

This multi select is fed from this database table (carriers).

Screen Shot 2017-04-05 at 9.38.17 AM.png

Users select one or more recipients from this select box to get an email when submitting the form.

The details of who is selected is stored in a database table called "shipping_bids_repeat_select_carriers" which stored the ID of the record from the carrier database table (carriers).

I need to grab the email addresses of those selected and I am struggling with the proper code to achieve this in the (eval) section.
Screen Shot 2017-04-05 at 9.43.30 AM.png

Does anyone have any sample code or can help with assisting me with the code I would use here to grab those emails in a comma separated list?

Thank you!
 
This may be a little more than you need... I am doing if else statements on mine...but hopefully it get's you started:

PHP:
$customer = '{ons_system___customer_raw}';
$market = '{ons_system___market}';
//$level = '{ons_system___level}';
//$level_raw = '{ons_system___level_raw}';
$severity = '{ons_system___severity}';

$db = JFactory::getDbo();
//var_dump($level); exit;
if ($severity == 'Level 1') {
$query = "select group_concat(DISTINCT email separator ', ') from ons_email_view WHERE (customers = " . $db->quote($customer) . " OR subscribe_to_all_customers = 1) AND (market = " . $db->quote($market) . " OR subscribe_to_all_markets = 1) AND level_1 > 1 AND status=1";
}
else if ($severity == 'Level 2') {
$query = "select group_concat(DISTINCT email separator ', ') from ons_email_view WHERE (customers = " . $db->quote($customer) . " OR subscribe_to_all_customers = 1) AND  (market = " . $db->quote($market) . " OR subscribe_to_all_markets = 1) AND level_2 > 1 AND status=1";
}
else if ($severity === 'Level 3') {
$query = "select group_concat(DISTINCT email separator ', ') from ons_email_view WHERE (customers = " . $db->quote($customer) . " OR subscribe_to_all_customers = 1) AND  (market = " . $db->quote($market) . " OR subscribe_to_all_markets = 1) AND level_3 > 1 AND status=1";
}
else if ($severity === 'Level 4') {
$query = "select group_concat(DISTINCT email separator ', ') from ons_email_view WHERE (customers = " . $db->quote($customer) . " OR subscribe_to_all_customers = 1) AND  (market = " . $db->quote($market) . " OR subscribe_to_all_markets = 1) AND level_4 > 1 AND status=1";
}
else if ($severity === 'Critical') {
$query = "select group_concat(DISTINCT email separator ', ') from ons_email_view WHERE (customers = " . $db->quote($customer) . " OR subscribe_to_all_customers = 1) AND  (market = " . $db->quote($market) . " OR subscribe_to_all_markets = 1) AND critical > 1 AND status=1";
}
$db->setQuery($query);
$email = $db->loadResult();
//var_dump($email, $query); exit;
return $email;
 
A simpler example:

PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$customer='{cpm___customer}';
$market='{cpm___market}';
$db->setQuery("select group_concat(DISTINCT email separator ', ') from service_delivery_contacts LEFT JOIN service_delivery_contacts_repeat_market ON service_delivery_contacts.id=service_delivery_contacts_repeat_market.parent_id WHERE customer = '{cpm___customer_raw}' AND service_delivery_contacts_repeat_market.market='{cpm___market}'");
$post = JRequest::get('post');
return $db->loadResult();
 
Thank you.

I have gotten this far with my sql query however I keep getting an error "Unknown column 'shipping_bids_repeat_select_carriers.parent_id' in 'on clause'"


PHP:
Here is my query:
select group_concat(DISTINCT `email_address` separator ', ') from `carriers` LEFT JOIN `shipping_bids_repeat_select_carriers` ON `carriers.id`=`shipping_bids_repeat_select_carriers.select_carriers` WHERE `shipping_bids_repeat_select_carriers.parent_id`='{$my-id}' AND `carriers.user_id` = '{carrier.id}'


But that column DOES exist....
Screen Shot 2017-04-05 at 9.43.12 PM.png

I appreciate the help.
 
Ok...put your query into phpmyadmin or whatever tool you are using and run the query in there...except remove your WHERE clause. What do you get?

Your WHERE...`carriers.user_id` ='{carrier.id}' should be something like `carriers.user_id` ='{carrier___id}'
 
I get the same error. #1054 - Unknown column 'carriers.id' in 'on clause'

It has something to do with the ON clause. I keep getting an error that the carriers.id (table.column) do not exist, but they do.
 
Oh...I see the issue

`shipping_bids_repeat_select_carriers.select_carriers` should be `shipping_bids_repeat_select_carriers`.`select_carriers`
 
Oh man. Thank you. I never use ` in my queries but added them to see the text better.

SOLVED
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top