I facing a huge problem with my site that provides an email alert. Whenever a user registers for e-mail alert, I get his email address and the application searches it in this form:
PHP Code:
SELECT ... FROM ... WHERE ...
I save everything in a table (t_alert_email). My problem lies in the script for sending email based alerts.
1 - I do a loop to retrieve requests from the table t_alert_email
2 - I do another nested loop to retrieve the references of addresses corresponding to these requests
3 - I still do a nested loop, in which I compare the references retrieved in step 2, with my t_addr table (table in which all the addresses are stored) according to the date.
4 - I do a loop to email the references retrieved in step 3 to the corresponding email.
My code:
PHP Code:
$date_of_day = date("Y-m-d" );
//Select queries stored in the alert table
$selection_infos_alert = mysql_query("SELECT id_alert, email, request FROM t_alert_email" );
//We make a loop to get queries
while ($results_infos_alert = mysql_fetch_array($selection_infos_alert)) {
//Results are assigned to the variable $selection_request_stock
$selection_request_stock = mysql_query($results_infos_alert['request']);
//We make a loop to the variable $selection_request_stock to retrieve references (ASP) corresponding to the request
while ($results_request_stock = mysql_fetch_array($selection_request_stock)) {
//Results are assigned to the variable $request_extraction_affairs
$request_extraction_affairs = mysql_query("SELECT * FROM t_addr WHERE t_addr.date_modif = '$date_of_day' AND t_addr.no_asp = '$results_request_stock['no_asp']'" );
//We make a loop to the variable $results_extraction_affairs to retrieve references to email
while ($results_extraction_affairs = mysql_fetch_array($request_extraction_affairs)) {
$request_definitive_envoi_alert = mysql_query("SELECT * FROM t_addr WHERE... AND t_addr.no_asp = '$results_extraction_affairs['no_asp']'" );
//We count the number of results returned
$nb_results = mysql_num_rows($request_definitive_envoi_alert);
/***** Shipping offers by email *****/
$address_email_alert = $results_infos_alert['email'];
$header = 'From: ...'."\n";
$header .= 'MIME-Version: 1.0'."\n";
$header .= 'Content-Type: text/html; charset="iso-8859-1"'."\n";
$header .= 'Return-Path: ...'."\n";
$header .= 'Content-Transfer-Encoding: 8bit';
if ($nb_results == '1') {
$subject = "1 new listing matches your criteria";
}
else {
$subject = $nb_results." new listings match your criteria";
}
$message =
"<html>".
"<head>".
"<title>Alert email...</title>".
...
...
...
while ($results_final_envoi_alert = mysql_fetch_array($request_final_envoi_alert)) {
$message .= "<p> </p>".
"<table width='350' border='0' cellspacing='0' cellpadding='0' class='bg1'>".
"<tr>".
"<td>".
'<p>'.$results_final_envoi_alert['wanted_internet'].'<br />'.$results_final_envoi_alert['price'].' Rs.</p>'.
"</td>".
"<td>".
"</td>".
"</tr>".
"<tr>".
"<td>".
"</td>".
"<td>".
"</td>".
"</tr>".
"<tr>".
"<td colspan='2'>".
"</td>".
"</tr>".
"</table>";
}
$message .=
...
...
...
...
"</td>".
"</body>".
"</html>";
}
}
}
mail($address_email_alert, $subject, $message, $header);
I receive many emails, but there is only one address instead of two that correspond to the test email alert, and I also do not get mail on a single email address.
Bookmarks