Hi,
I'm struggling with this for days now. Could anyone help me? I have the below code that I run daily, and which sends notification mail to members if there is an ad in the "ad" table that matches specific criteria saved in "notice" table. Works like the feature on job sites.
But this code sends every matching ad in separate mail. What do I need to modify in this code to make it send one email per member with the ads listed in it like:
Subject of ad 1
Link for ad 1
Subject of ad 2
Link for ad 2
Subject of ad 3
Link for ad 3
.
.
.
etc.
Thanks for your help guys!
$day = $time - 3600 * 24;
$oneday = mysql_query("SELECT * FROM $ads_tbl WHERE add_date>$day") or error(mysql_error());
$i = 1;
while($rowday = mysql_fetch_array($oneday))
{
$ad_id = $rowday['ad_id'];
$biztype = $rowday['biztype'];
$subject = $rowday['subject'];
$descript = $rowday['descript'];
$cat_id = $rowday['cat_id'];
$territory = $rowday['territory'];
$terr1 = explode(", ", $territory);
$qstring ="AND (";
foreach($terr1 as $temp1)
{
$qstring .= " territory LIKE '%".$temp1."%' ";
$qstring .= "OR";
}
$qstringend = ")";
$qstring2 = substr($qstring, 0, -3);
$qry = "SELECT email, territory FROM $notice_tbl
WHERE biztype='$biztype'
AND cat_id='$cat_id'
$qstring2
$qstringend";
$notice = mysql_query($qry);
while($rowmail = mysql_fetch_array($notice))
{
$from = "New Ad Notice <$ADMIN_EMAIL>";
$to = $rowmail['email'];
$mailsubject = "New ad listing from $ADVT_NAME";
$body = "Dear Member,
This is a new ad from $ADVT_NAME
$subject
{$ADVT_URL}/ads/view.php?id=$ad_id
";
sentMail($from, $to, $mailsubject, $body);
}
}