Forums

[SOLVED] send dynamic e-mail with database data

laurentmartin 01 May, 2011
Hello,

I have a database (jos_user) including id, username, firstname, name, e-mail address.

I populate a dropdown list in a form by callingback the data firstname and name, meaning my dropdown display "Firstname Name" in its list?

I need to send an e-mail by clicking on submit with some {data} in the template to the user i select in the dropdown. It means i need from the dropdown selection get back the e-mail of the user i selecgted based on name and firstname .

Any idea how to to get back the e-mail from the database based on the choice in the dropdown to pass the e-mail address to populate the "Dynamic to" field ?

Thanks for your help.

Regards
GreyHead 01 May, 2011
Hi laurentmartin,

Use the User id as the value for the drop down; then look up the email from the Joomla! User object in the OnSubmit Before Email box:
<?php
$user_id = JRequest::getInt('user', '', 'post');
$user = JRequest::getUser($user_id);
JRequest::setVar('user_email', $user->email);
?>
Then use user_email in the Dynamic To box.

Bob
laurentmartin 01 May, 2011
does it work if the database is not jos_user?

I mean what i want is to send e-mail to the user i selected in the dropdown not the user using the interface currently.

I am not sure if you understood my request ?
I use this code fro now to get back the data from the databse:

<div class="form_item">
  <div class="form_element cf_dropdown">
   <label class="cf_label" style="width: 150px;">Select Person</label>
    <select class="cf_inputbox validate-selection" id="cf_user_id" size="1" title=""  name="cf_user_id">
    <option value="">Choose Person</option>
    <?php
    $db =& JFactory::getDBO();
    $query = "
      SELECT *
        FROM #__person ";
    $db->setQuery($query);
    $rows = $db->loadObjectList();

foreach ($rows as $row) {
      echo "<option value='$row->id'>$row->person_country.$row->person_state.$row->i_city.$row->person_name</option>";
}
    ?>
    </select>
    </div>
</div>


I also have a field person_email
GreyHead 02 May, 2011
Hi laurentmartin,

Sorry for the delay, just been busy.

I misunderstood your request as you talked about jos_user I thought you were referring to the standard Joomla! jos_users table which has all of those columns.

For your custom table the code would be like this:
<?php
$cf_user_id = JRequest::getInt('cf_user_id', '', 'post');
$db =& JFactory::getDBO();
$query = "
    SELECT `email`
        FROM `#__person`
        WHERE `cf_user_id` = '$cf_user_id' ;
";
$db->setQuery($query);
$email = $db->loadResult();
JRequest::setVar('user_email', $email);
?>

Bob
laurentmartin 04 May, 2011
Hi Bob,

I sent you a PM.

Can you check at it and reply to me in PM please ?

Thanks
GreyHead 04 May, 2011
Hi laurentmartin,

I suspect that there is a problem with this line:
echo "<option value='$row->i_country'>$row->i_name.$row->i_email1</option>";
where the variables need to be 'quoted'
echo "<option value='{$row->i_country}'>{$row->i_name} {$row->i_email1}</option>";


And, although the value of these options is showing the country you are checking that against the stored cf_user_id in the look up query.

Hard to say anything more without seeing what is actually happening in the form.

Bob
laurentmartin 04 May, 2011
Hi Bob,

What do you need more ?

For now it is still doesn't work. It says : You must provide at least one recipient e-mail address.
GreyHead 04 May, 2011
Hi laurentmartin,

I still don't see how having the country in the options value helps you get the cf_user_id when you look up the email?

Bob
laurentmartin 05 May, 2011
Hi Bob,
I am not a coder unfortunately.
can you suggest me something since you know the organization of my form and of my database ?

Thanks in advance
GreyHead 09 May, 2011
Hi laurentmartin,

The form workflowchoiceinspec is now working correctly. As I wrote earlier it wasn't helpful to set the value of the options to the inspector's country. I have changed this to the inspector's id.

I have also cleaned up various places where you have used cf_id and cf_user_id in conflicting ways by calling the inspector's id 'ins_id'.

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

VPS & Email Hosting 20% discount
hostinger