Hello everyone, firstly thanks for providing this great community.
I am tinkering with PHP/MySQL, part of a Joomla site. What this component does is send emails to “potential customers” who have subscribed to receive emails. Each email that is sent should also greet the user by their name.
So for example, in my DB table I might have 4 people
id | first_name | last_name | email | [etc...]
-----------------------------------------------------
25 | Jim | Dandy | [email protected] |
26 | Fred | Smith | [email protected] |
27 | Jill | Jackson | [email protected] |
28 | Ann | Johnson | [email protected] |
My code happily mails out emails to all these people in the DB; Jim gets an email sent to his address, Ann gets one to her email, etc. etc. but it is greeting them all by the name Jim!!! (i.e., first entry in the database). Also, the ID number is used to generate an unsubscribe link, so it knows who to unsubscribe, but they are all also being assigned ID #25.
So I cannot understand why they are all getting the emails (i.e., the script is working its way through each row in the table) but it is not cycling through the first_names or ids.
I have included the code below of the controller for this component. If there is any generous soul out there who might know what the problem is, or can at least offer some sort of hint that might get me on the right track, I’d be most grateful. Obviously I am quite out of my depth here but feel I am very close to fixing it!
I have included only the parts of the code that are directly relevant for the sake of brevity.
Thank you in advance for the ideas! 
[php]
<?php // No direct access defined( '_JEXEC' ) or die( 'Restricted Access' ); ?> <?php /** * Potential customer Controller */ class PotentialcustomersControllerPotentialcustomer extends PotentialcustomersController { /** * Method to get email-template */ function get_emailTemplate($title) { $db = &JFactory::getDBO(); $query = "SELECT * FROM #__emailtemplates WHERE template_title='".$title."'"; $db->setQuery($query); $row = $db->loadObject(); return $row; } /** * Method to get details about the people receiving the emails. */ function get_potentialcustomerDetails($id) { $db = &JFactory::getDBO(); $query = "SELECT * FROM #__potentialcustomers WHERE id='".$id."'"; $db->setQuery($query); $potentialcustomer_rs = $db->loadObject(); return $potentialcustomer_rs; } /** * send mail to subscribers */ function send() { $db = &JFactory::getDBO(); // Initialize variables $confige = &JFactory::getConfig(); $emailTemplate_bulkmail = $this->get_emailTemplate('bulkmail_potentialcustomer'); $subject = $emailTemplate_bulkmail->template_subject; $body = $emailTemplate_bulkmail->template_body; $cids = JRequest::getVar( 'cid', array(0), 'post', 'array' ); if (count($cids)) { foreach($cids as $cid) { $potentialcustomer_rs = $this->get_potentialcustomerDetails($cid); $name = ucfirst(trim($potentialcustomer_rs->first_name)); //all get greeted as same first name :( $course_title = $this->get_courseTitle($potentialcustomer_rs->courses_enquired); $from = $confige->getValue('mailfrom'); $fromname = $confige->getValue('fromname'); $sitename = $confige->getValue('sitename'); $siteurl = ''.$sitename.''; $unsubscribe_url = JRoute::_( JURI::base().'index.php?option=com_subscribe&sid='.$cid.'&cid='.$potentialcustomer_rs->courses_enquired ); //see here, ?option=com_subscribe&sid='.$cid [etc.] gives each email the same id. $unsubscribe_link = 'Unsubscribe'; $recipient = $potentialcustomer_rs->email; //yet here, they all get the emails to their own addresses. $follow_up = $potentialcustomer_rs->followup; $body = eregi_replace("[\]", '', $body); $body = str_replace('[site name]', $sitename, $body); $body = str_replace('[site url]', $siteurl, $body); $body = str_replace('[enquirer\'s name]', $name, $body); $body = str_replace('[enroller\'s name]', $name, $body); $body = str_replace('[course\'s title]', $course_title, $body); $body = str_replace('[unsubscribe link]', $unsubscribe_link, $body); $body = html_entity_decode($body, ENT_QUOTES); if(JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode=1)) { $query_update = "UPDATE jos_potentialcustomers SET followup='".++$follow_up."' WHERE id='".$cid."'"; $db->setQuery( $query_update ); $db->query(); } } $msg = JText::_( 'Mail Sent.' ); $this->setRedirect( 'index.php?option=com_potentialcustomer', $msg ); } } } [/php]