I have a php script which requires phpmailer and I got it to work already but I need to send the email to 3000 persons. How do I do that? I've tried searching over the net but all the examples show only to enumerate the emails addresses. Mine comes from a database with queries. I have the following code :

$mail             = new PHPMailer();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->SMTPAuth      = true;
$mail->SMTPKeepAlive = true;
$mail->Port          = 465;  
$mail->Username      = "my@gmail.com";
$mail->Password      = "password";
$mail->SetFrom('my@email.com', 'First Last');
$to = "my@gmail.com";
$mail->AddAddress('$to',"First Last");
$mail->Subject = "Test Mail";
$message = "messages go here";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo "An e-mail was sent to $to with the subject: $subject";;}

Any suggestion is appreciated. Thanks!

5 Years
Discussion Span
Last Post by Tpojka

So what exactly are you looking for? If it is looping query results, then there are examples in the code snippets.


which code snippets? I haven't found sources wherein they use query results from the database and loop it. Can you help?

EDIT: I meant I wanted to know how I could email to multiple BCC's.

Edited by tscina


I made some research and some say that using phpmailer moves the sent mail to the spam folder. Can you give me advice on this?


It's possible, but then again: I'm sure if you send me a regular email there's a good change that will land in my spam too. There are ways to add headers to provide more trustworthy information in the email, so it won't get flagged as easy. But there's always the change it gets flagged. The people who blurt out such statements rarely back it up IMHO.


I'm trying to learn swiftmailer but the problem is it should have arrays for the to and from addresses. I use dreamweaver so when I make queries, it generates its own codes so I'm not sure how I can code $address => $name and loop codes on my own if dreamweaver generates codes like this

<?php require_once('lib/swift_required.php'); ?>
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  return $theValue;

mysql_select_db($database_mail, $mail);
$query_get_sender = "SELECT * FROM `from`";
$get_sender = mysql_query($query_get_sender, $mail) or die(mysql_error());
$row_get_sender = mysql_fetch_assoc($get_sender);
$totalRows_get_sender = mysql_num_rows($get_sender);

mysql_select_db($database_mail, $mail);
$query_get_recipient = "SELECT * FROM `to`";
$get_recipient = mysql_query($query_get_recipient, $mail) or die(mysql_error());
$row_get_recipient = mysql_fetch_assoc($get_recipient);
$totalRows_get_recipient = mysql_num_rows($get_recipient);

$transport = Swift_SmtpTransport::newInstance($row_get_sender['smtp_host'], $row_get_sender['smtp_port'])

$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance()

                ->setSubject('Test Mail')

$result = $mailer->send($message);      



You could open new topic.
But answer to your question could be done with Mailchimp service.
And if you want to use it dinamically from your PHP application, you can use their API system.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.