Results 1 to 2 of 2

Thread: Mailing to multiple addresses

  1. #1
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Mailing to multiple addresses

    I'm trying to notify (certain members) of my site, when I upload new pictures. The php code will send out the email but, only to one person. I'm trying to send it to everyone with the set_note "2" if that makes any sense. I'm still learning and any help would be greatly appreciated....


    Code:
    <? 
    include_once "accesscontrol.php";
    $notify = 2;
    
    $q11 = "select * from members_info where set_note = \"$notify\" ";
    $r11 = mysql_query($q11) or die(mysql_error());
    $a11 = mysql_fetch_array($r11);
    
    
    
    if( !empty( $a11 ) )
    {
        $to = $a11[members_email];
    	$subject = "New Pictures Posted";
    	$message = "Dear $a11[fname],\n\nWe posted some new baby pictures on our website. Please login to www.$_SERVER[HTTP_HOST] to view the album.\n\nIf you want to stop getting these automatic notices, please login and change your profile settings.\n\nThanks\nJustin";
    	$from = "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>";
    
    	mail($to, $subject, $message, $from);
    }
    
    
    ?>
    
     <table align="center" width="600" cellpadding="0" cellspacing="0">
      <tr><td align="center"><br /><br /><b>Notified Participating Members!</b></td></tr>
    
    
    
    
    </table>
    
    <? include("../footer.php"); ?>
    Last edited by djr33; 03-14-2010 at 05:54 AM. Reason: fixed [code] tags

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The simple explanation is that you are only getting one row from the database:
    mysql_fetch_array() gets one row and then you can do things with it. Use it another time and it will magically grab the next row. Repeat until there are no results (it will return 'false' instead of a new row).

    The traditional way to write this is:
    PHP Code:
    $query "SELECT 'x' FROM 'table';";
    $result mysql_query($query);
    while (
    $row mysql_fetch_array($result)) { //loop through all rows, until no more exist
       
    echo $row['x'];

    You can easily apply the same method here.

    Alternatively you could put them all into a single array (list of emails) then send to all using a single mail() line, but that would show them each their email addresses (using "CC").



    To find out more about mysql, take a look at this website, starting with the "last" tutorial which was posted first, which will (as of posting) be on page 2:
    http://php-mysql-tutorial.com
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •