Sending email in a loop using Jutility::SendMail

Pag usapan ang mga bagay na ukol sa pangkalahatang interes sa web at Joomla!
Locked
sochdeveloper
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Apr 07, 2011 6:55 am
Location: Zimbabwe
Contact:

Sending email in a loop using Jutility::SendMail

Post by sochdeveloper » Mon May 02, 2011 5:21 pm

l am trying to send an email to a list in batches of 50.

The problem is when l get the emails from the database and then loop through sending emails l experience email bombarding i.e l get about 12 emails to one emails.

User avatar
popa alexandru
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Sun Sep 05, 2010 7:33 am
Contact:

Re: Sending email in a loop using Jutility::SendMail

Post by popa alexandru » Mon May 02, 2011 8:13 pm

Very weird thing.You can provide the part of php code you use to make this sending e-mails loop ?
Can be something wrong there.
Joomla! Extensions
http://www.beesto.com

sochdeveloper
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Apr 07, 2011 6:55 am
Location: Zimbabwe
Contact:

Re: Sending email in a loop using Jutility::SendMail

Post by sochdeveloper » Tue May 03, 2011 7:58 am

l have got something like below.
$sql = SELECT `email` FROM `#__members` WHERE `premium` = '1' LIMIT 50
$db->setQuery($sql);
$res = $db->loadObjectList();
//l import the mailer here
foreach($res as $r)
{
$emailto = $r->email;
then l send the email here using Jutility::Sendmail()
}
l skipped the actuall code because l know the code is correct so l just gave the logic l am following

sochdeveloper
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Apr 07, 2011 6:55 am
Location: Zimbabwe
Contact:

Re: Sending email in a loop using Jutility::SendMail

Post by sochdeveloper » Tue May 10, 2011 8:41 pm

function 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();
}


Locked

Return to “Pinoy General Discussion & Archives”