Results 1 to 3 of 3

Thread: Problem of email alert in PHP

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    271

    Re: Problem of email alert in PHP

    Your problem lies in your code,
    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++; 


  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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?

Similar Threads

  1. AVAST popup Trojan alert redirBA-inf and Malware alert script-inf
    By Wajid^ali in forum Networking & Security
    Replies: 6
    Last Post: 06-06-2011, 01:38 AM
  2. UPS email virus - ALERT
    By Xeusion in forum Networking & Security
    Replies: 12
    Last Post: 17-11-2010, 04:37 AM
  3. Replies: 3
    Last Post: 13-08-2009, 07:07 PM
  4. Solving a problem with Red Alert 3
    By Shaji in forum Video Games
    Replies: 0
    Last Post: 06-02-2009, 03:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,049,926.78260 seconds with 16 queries