Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 2 of 2

Thread: PHP mail with multiple addresses

  1. #1
    102
    posts
    Registered User

    PHP mail with multiple addresses

    I'm trying to send an email to everyone from a database list. I have attached the code. For some reason this code never sends the emails out. It only works if the $to variable is set to one person and one person only.

    Code:
    $to = "matthew.oconnor@comcast.net";
    but here is the code that doesn't work. Any hints?
    Code:
    <?php
    mysql_select_db($database_connPavlishDB, $connPavlishDB);
    $query_rsSpecials1 = "SELECT * FROM specials";
    $rsSpecials1 = mysql_query($query_rsSpecials1, $connPavlishDB) or die(mysql_error());
    $row_rsSpecials1 = mysql_fetch_assoc($rsSpecials1);
    $totalRows_rsSpecials1 = mysql_num_rows($rsSpecials1);
    
    mysql_select_db($database_connPavlishDB, $connPavlishDB);
    $query_rsEmails = "SELECT * FROM customers";
    $rsEmails = mysql_query($query_rsEmails, $connPavlishDB) or die(mysql_error());
    $row_rsEmails = mysql_fetch_assoc($rsEmails);
    $totalRows_rsEmails = mysql_num_rows($rsEmails);
    ?> 
    
    <?php $var1 = "Here are the current specials at Pavlish Beverage.\n\n"?>
    <?php do { ?>
    <?php 
    $var1 .= $row_rsSpecials1['name'];
    $var1 .= " ";
    $var1 .= $row_rsSpecials1['quantity']; 
    $var1 .= " for ";
    $var1 .= $row_rsSpecials1['price'];
    $var1 .= ".\n" 
    ?>
    <?php } while ($row_rsSpecials1 = mysql_fetch_assoc($rsSpecials1)); ?>
    <?php $var1 .= "\n\nHave A Good 1!\n\nPavlish Beverage\n(610)866-7722\nhttp://www.PavlishBev.com" ?>
    
    <?php do { ?>
    <?php 
    $var2 = $row_rsEmails['email']; 
    $var2 .= ",\n";
    ?>
    <?php } while ($row_rsEmails = mysql_fetch_assoc($rsEmails)); ?>
    
    <?php  
    $to = "$var2";
    $subject = "Pavlish Beverage Alert!";
    $message =  "$var1";
    
    mail($to,$subject,$message);
    ?>

  2. #2
    102
    posts
    Registered User
    i fixed it!

    Basically i wrote in one permanent address, then looped thru the others, than added another permanent one so that last ", " wasnt just hanging off the end there. I discovered you need a comma, then space to separate email addresses in PHP.

    now does anyone know if i can make these invisible to the individual users?

    Code:
    <?php 
    $var2 = "matthew.o'connor@lmco.com";
    $var2 .=", ";
    ?>
    <?php do { ?>
    <?php 
    $var2 .= $row_rsCustomers['email'];
    $var2 .= ", ";
    ?>
    <?php } while ($row_rsCustomers = mysql_fetch_assoc($rsCustomers)); ?>
    <?php 
    $var2 .= "matthew.oconnor@comcast.net";
    ?>
    
    <?php  
    $to = "$var2";
    $subject = "Pavlish Beverage Alert!";
    $message =  "$var1";
    $from = "Pavlish Beverage";
    $from_header = "From: $from";
    
    mail($to,$subject,$message,$from_header);
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012