I'm trying to use phpmailer and a database. here's the script that i have formulated to get the message and subject, fromname, and addresses of recepients.

I want to get the list of emails from the database, add them to an array, and send the email. When i get the list from the database and echo it, it just says ARRAY. What can I do?

<?php
//processing the mass email form.
require("class.phpmailer.php");
include '../includes/connect.php';
include '../includes/pass.inc.php';
//put all of the selected addresses into an array called email
$name = $_POST['fromname'];
$fromadd = $_POST['from'];
$body = $_POST['body'];
$subject = $_POST['subject'];
$name = htmlspecialchars($name, ENT_NOQUOTES);
$fromadd =  htmlspecialchars($fromadd, ENT_NOQUOTES);
$subject = htmlspecialchars($subject, ENT_NOQUOTES);
$body = htmlspecialchars($body, ENT_NOQUOTES);

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->From     = $fromadd;
$mail->FromName = $name;
$mail->Host     = "mail.truman.edu";


$query  = "SELECT email FROM brothers";
$result = mysql_query($query);


//$adds = file('addresses.txt');   // read the addresses file into an array

//foreach($adds as $address)    // loop through the array adding the email addresses to the mailer

/*gets one address, then sends email, and clears address, and gets next.
while ($row = mysql_fetch_array ($result))
{

// Plain text body (for mail clients that cannot read HTML)

$mail->Body    = $body;
$mail->Subject = $subject;
$mail->From    = $fromadd;
$mail->FromName = $FromName;
$mail->AddAddress($row['email']);

if(!$mail->Send())
    echo "There has been a mail error sending to " . $row["email"] . "<br>";


// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
}*/
header("location: [url]http://dsp.truman.edu/email/success.php[/url]");
?>

    Don't follow you. Where is the error arising? I presume you are trying to echo the email adr to debug another problem. If you want to see what is in the query results then

    print_r($result)

    will list the contents.

      it's not so much an error as there is a better logical way to write the script. I want to send an email to everyone in this group. the commented out script creates one email for each address in the database which takes too long and the script times out on the server after 30 seconds and only sends about half of the emails. I want to instead of doing it that way, get all the email addresses at once and send one email. I'm just not sure how to get all the emails and put them in the $address field.

        You can get your email server to handle that by putting all of the seperate email addresses into a Bcc (blind carbon copy) list. I'm not familiar with phpMailer but I'm sure it can accept a Bcc list. The sever then transmitts a copy to evreyone on the list.

        If the list is a stable group then you could also set up an email group on your server and send one email to the group. The server handles transmission to group members. This of course is server dependent.

          that's not really what i care about. I don't care if all the members on this list can see each other and their addresses.

          I just want all of the addresses to be read into one array or text line so that the script only sends one email.

          example::

          to: something@fdsa.com, somethinelse@truman.edu, etc.

          currently it's doing this:

          somethin@fdsa.com
          email
          clear addresses
          somethinelse@truman.edu
          email
          clear addresses
          and so on.

          i just need a way to get all of the email addressses out of the database, into one variable so that the email only gets sent once and doesn't take very long to process.

          all i'm doing now is fetching the email addresses

          <?php
          $sql = select email from brothers;
          $result = mysql_query($sql);
          while ($row = mysql_fetch_array($result)){
          $adds = print_r($row);
          echo $adds;
          ?>
          This somewhat accomplishes what I want but not really.  I just want all the email addresses at the same time.

            Same as you would if you wanted them in a list for CC or BCC.

            // set up an array for emails
            $ary = array();
            while ($row=mysql_fetch_array($result)) {
               // add email addr to array
               $ary[] = $row['email'];
            }
            // convert email array into a comma delimited string and terminate string with semi-colon
            $to = implode(',' , $ary) . ';' ;
            
            

            The format for the $to string is for mail() function, don't know the format for phpMailer.

              Write a Reply...