Email plugin

jh

Member
Hi

I was setting up some email plugins which are working fine however one that I can not work out is:

How to email the original submitter of the details that their record has been used on another form (via database join). The record has a 'submitted by' user element/id field, and I want them to be emailed when someone 'uses' that record. Hope this makes sense.

Kind Regards
 
You'd have to use the "Email to (eval)" feature, to get the email from the user id of the related record.

Code:
// get the join's value (foreign key), replace yourtable___yourjoin with the full element name, leave the _raw suffix
$joinId = (int)'{yourtable___yourjoin_raw}';
if (!empty($joinId)) {
   $db = JFactory::getDbo();
   $query = $db->getQuery(true);
   // replace yourtable and userid with your table name and user field name as appropriate
   $query->select('u.email')->from('yourtable')->leftJoin('#__users AS u ON u.id = yourtable.userid)->where('yourtable.id = ' . $joinId);
   $db->setQuery($query);
   return $db->loadResult();
}
return '';

-- hugh
 
Hi

Thank your for your message. So if table 1 is named 'object_table' with user field name 'sub' and table 2 is named 'collection_new' with the database join field 'collection_new___datajoin' should this work? (I want the user who submitted the record to be emailed when someone adds it to their own list)


// get the join's value (foreign key), replace yourtable___yourjoin with the full element name, leave the _raw suffix
$joinId = (int)'{collection_new___datajoin_raw}';
if (!empty($joinId)) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// replace yourtable and userid with your table name and user field name as appropriate
$query->select('u.email')->from('object_table')->leftJoin('#__users AS u ON u.id = object_table.sub)->where('object_table.id = ' . $joinId);
$db->setQuery($query);
return $db->loadResult();
}
return '';

Thank you for your help.
 
Hi

Thank you I have tried this and got an error page:

syntax error, unexpected 'object_table' (T_STRING), expecting ',' or ')'

Is there something I might have done wrong?

Many thanks
 
Thank you both, works perfectly.

Could I ask how to get placeholders for the email from the list containing the foreign key (the new form does not contain the data, only the db join)

Thank you very much for your help.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top