Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11-05-2009
Member
 
Join Date: Feb 2008
Posts: 324
Problem of email alert in PHP

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>&nbsp;</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.
Reply With Quote
  #2  
Old 11-05-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: Problem of email alert in PHP

Your problem lies in your code,
Quote:
mail($address_email_alert, $subject, $message, $header);
at the end. What your are doing is that you tell PHP to send email 1 time so it's normal that you receive a single email

I would say include this statement in your loop where you retrieve the addresses, something like this:

PHP Code:
$i 1
while(
$i<=$nb_results){ 
     
mail($address_email_alert[$i], $subject$message$header); 
     
$i++; 

Reply With Quote
  #3  
Old 11-05-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Problem of email alert in PHP

I agree with XSI. Also I would like to add to this is that try to execute once and send your mail because it don't work always .

You must place your "mail($address_email_alert, $subject, $message, $header);" at the end of the first loop that manages emails.

And you defined $address_email_alert in your third loop, there is no logic defining it there because $results_extraction_affairs will be empty. One more thing, you didn't specified the destination email address?
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem of email alert in PHP"
Thread Thread Starter Forum Replies Last Post
AVAST popup Trojan alert redirBA-inf and Malware alert script-inf Wajid^ali Networking & Security 6 06-06-2011 01:38 AM
UPS email virus - ALERT Xeusion Networking & Security 12 17-11-2010 04:37 AM
How to stop my blackberry phone from beeping / Alert on every email Kingfisher Portable Devices 3 13-08-2009 07:07 PM
Solving a problem with Red Alert 3 Shaji Video Games 0 06-02-2009 03:24 PM


All times are GMT +5.5. The time now is 05:08 PM.