data['mailarray'] = $row['email']; }Any ideas/suggestion how I should do this? Thanks!"> Mailform to group of people from db - Forums

Forums

Mailform to group of people from db

brononius 20 Aug, 2013
Hey,

I've created a database where my users (joomla users and CB) can point out that they would like to recieve emails.
So now I'm trying to make a form that allows me to send a mail directly to all recipients.


This code gives me a nice overview of all the users their email, and with the echo I putted a , in between.
$result = mysql_query("
   SELECT email FROM voc_users 
   LEFT JOIN voc_comprofiler 
   ON voc_users.id = voc_comprofiler.user_id 
   WHERE cb_mailing = 1
   "); 
 
while ($row = mysql_fetch_assoc($result)) {
   echo "" . $row['email'] . ", ";
   }


But I would like to put the echo now in a variable (?) so that I can use this later on in a mailform. When I put this into an array, I've got only the latest mail address (not all).
$result = mysql_query("
   SELECT email FROM voc_users 
   LEFT JOIN voc_comprofiler 
   ON voc_users.id = voc_comprofiler.user_id 
   WHERE cb_mailing = 1
   "); 

while ($row = mysql_fetch_assoc($result)) {
   $form->data['mailarray'] = $row['email'];
   }



Any ideas/suggestion how I should do this?



Thanks!
GreyHead 20 Aug, 2013
Hi brononius,

First, I don't think that the standard Email action will accept a variable with a string of emails in it; but my Email [GH] action will accept either a string or an array (it also has an option to send out separate emails to each address).

So this code would work I think:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT `email`
  FROM `#__users` AS u
  LEFT JOIN `#__comprofiler` AS c
   ON u.`id` = c.`user_id`
  WHERE `cb_mailing` = 1 ;
";
$db->setQuery($query);
$form->data['to_emails'] = $db->loadResultArray();
?>

Bob
brononius 20 Aug, 2013
Is it normal that in a debug, the 'to_emails' stay empty?

If I run the sql query in phpmyadmin, the result is correct.
brononius 20 Aug, 2013
Not sure if it's good, but this seems to work with your action:

$result = mysql_query("
SELECT email FROM voc_users
LEFT JOIN voc_comprofiler
ON voc_users.id = voc_comprofiler.user_id
WHERE cb_mailing = 2
");

while ($row = mysql_fetch_array($result)) {
$mailarray[] = $row['email'];
}
$form->data['to_emails'] = $mailarray;

GreyHead 20 Aug, 2013
Hi brononius,

If it works, it's OK.

Maybe loadAssocArray() doesn't work in the current Joomla! :-(

Bob
brononius 20 Aug, 2013
Thanks a lot!

I really enjoy playing around with chronoforms and learned a lot from it...
Keep up the good work!!!
This topic is locked and no more replies can be posted.