l havinf problems sending individual emails with a loop within joomla

The code is sending multiple emails to a single users something like its triggering an infinite loop.

Please see code below

unction sendRequests()
{
$db = & JFactory::getDBO();
$sql = "SELECT *
FROM `#__quotehunter_hunt_quotes`
WHERE `flag` = '0'
LIMIT 1";
$db->setQuery($sql);
$quotereq = $db->loadObject();
if (count($quotereq) == 0)
{
exit();
}
$site = JURI::Root();
$body = '<html>
<head>
<title>
Your Free Email
</title></head><body><table align="center" width="600" style="font-family: Arial; color: #666666; font-size: 12px; border: 1px solid #e5e5e5; background: #E8F5E6;">';
$body .= '<tr>
<td colspan="4">' . $image . '</td>
</tr>';
$body .= '<tr>
<td colspan="4" style="color: #666666; border: 1px solid #e5e5e5; border-spacing: 1px;"><h4 style="font-family: Tahoma">PLEASE FIND BELOW DETAILS OF A REQUEST FOR QUOTE IN ONE OF THE CATEGORIES YOU HAVE AN ENTRY</h4></td>
</tr>';
$body .= '<tr>
<td style="background: #666666; color: #000000; border: 1px solid #e5e5e5; border-spacing: 1px;">Contact Person</td>
<td style="background: #666666; color: #000000; border: 1px solid #e5e5e5; border-spacing: 1px;">Company</td>
<td style="background: #666666; color: #000000; border: 1px solid #e5e5e5; border-spacing: 1px;">Email Address</td>
<td style="background: #666666; color: #000000; border: 1px solid #e5e5e5; border-spacing: 1px;">Due Date</td>
</tr>';
$body .= '<tr>
<td style="color: #666666; border: 1px solid #e5e5e5; border-spacing: 1px;">' . $quotereq->name . '</td>
<td style="color: #666666; border: 1px solid #e5e5e5; border-spacing: 1px;">' . $quotereq->company . '</td>
<td style="color: #666666; border: 1px solid #e5e5e5; border-spacing: 1px;">' . $quotereq->email . '</td>
<td style="color: #666666; border: 1px solid #e5e5e5; border-spacing: 1px;">' . $quotereq->due_date . '</td>
</tr>';
$body .= '<tr>
<td colspan = "4" style="background: #666666; color: #000000; border: 1px solid #e5e5e5; border-spacing: 1px;">Specific Requirements</td>
</tr>';
$body .= '<tr>
<td colspan="4" style="color: #666666; border: 1px solid #e5e5e5; border-spacing: 1px;">' . $quotereq->wanted . '</td>
</tr>';
$body .= '</table></body></html>';
$body .='<p> Submitted From ' . $_SERVER['REMOTE_ADDR'] . '</p>';
//get last id in case of more than 500
$latstitem = QuoteHunterHelper::getResult('#__quotehunter_temp', 'quote');
$sql1 = "SELECT `itemid` FROM `#__sobi2_cat_items_relations` WHERE `catid` = '$quotereq->category' AND `itemid` > '$latstitem' LIMIT 50";
$db->setQuery($sql1);
$comps = $db->loadObjectList();
if (count($comps) == 0)
{
QuoteHunterHelper::genericUpdate('#__quotehunter_temp', 'quote', 0);
$this->updateFild('#__quotehunter_hunt_quotes', 'id', $quotereq->id, 'flag', '1');
exit();
}
foreach ($comps as $comp)
{
$item = $comp->itemid;
$sql2 = "SELECT DISTINCT(`data_txt`) FROM `#__sobi2_fields_data` WHERE `fieldid` = '7' AND `itemid` = '$item'";
$db->setQuery($sql2);
$emailto = $db->loadResult();
QuoteHunterHelper::dispatchEmail($emailto,$body);
}
QuoteHunterHelper::genericUpdate('#__quotehunter_temp', 'quote', $item);
exit();
}

Recommended Answers

All 2 Replies

line 62 and 63. comment line 63 and echo emilto as done below

$emailto = $db->loadResult();
//QuoteHunterHelper::dispatchEmail($emailto,$body);
echo $emailto;

See whether you are getting expecting email ids on screen or not;

line 62 and 63. comment line 63 and echo emilto as done below

$emailto = $db->loadResult();
//QuoteHunterHelper::dispatchEmail($emailto,$body);
echo $emailto;

See whether you are getting expecting email ids on screen or not;

l have done tha before and l get the expected email addresses.

l have also tried to send the email only to one person and exit the loop and the email goes correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.