?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?Re: How to use PHP to send 500 emails ?
Author:??(---.ym.rnc.net.cable.rogers.com)
Date:???10-23-03 13:09

is this an individually addressed email or ca it go to multiple people at once?

will assume group of 50 people at once


$sql="select name, email from people_table";

$result = mysql_query($sql) or die ("Can't connect because ".mysql_error());

if (!$result){
echo "there was an error. please hit the back key and try again";
}else{

//go thru the list and create the email

//create counters
$x=1; $g=0;

//set the destination
$to="";

//figure out the no of emails to be sent and the no of groups
$num_elements = mysql_num_rows($result);

//figure out the total number of groups of 50 emails
$total_email_groups = floor($num_elements/50);

//figure out the remainder of emails to send in last group
$total_remainder= $num_elements -($total_email_groups * 50);


while ($rows=mysql_fetch_array($result)){

$name=$rows['name']; //required for individual msg
$email=$rows['email']; //get the email

if ($x==1){
//only need to set the below once
$subject = "Whatever my subject is";
$message = "body of message here(can be html with appropriate headers)";

//add the headers to create the html email
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: $your_name<$email>\nX-Mailer: PHP Automated Mailer";
}//end if

//start the loop to send 50 emails at a time or last group
if ($x==50)||(($g==$total_email_groups)&&{$x==$total_remainder)){
//if 50 email destinations then send
mail ($to, $subject, $message, $headers);
sleep(300); //wait 5 min to allow email server to send out the emails
$x=1; //reset the email counter
$to=""; //reset destination
$g++; //increase the group counter

}else{
$to.=$email.";"; //add the email to the list
$x++;
}

}//end while

}//end if

needs to be tested

?Topics Author? Date
?How to use PHP to send 500 emails ???new
Mark 10-02-03 12:12?
?Re: How to use PHP to send 500 emails ???new
? 10-02-03 12:43?
?Re: How to use PHP to send 500 emails ???new
bastien 10-02-03 20:04?
?Re: How to use PHP to send 500 emails ???new
Chris 10-06-03 00:39?
?Re: How to use PHP to send 500 emails ???new
petetola 10-20-03 17:09?
?Re: How to use PHP to send 500 emails ???new
bastien 10-23-03 13:09?
Go to Top??|??Go to Topic??|??Flat View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??wrote: > > is this an individually addressed email or ca it go to > multiple people at once? > > will assume group of 50 people at once > > > $sql="select name, email from people_table"; > > $result = mysql_query($sql) or die ("Can't connect because > ".mysql_error()); > > if (!$result){ > echo "there was an error. please hit the back key and try > again"; > }else{ > > //go thru the list and create the email > > //create counters > $x=1; $g=0; > > //set the destination > $to=""; > > //figure out the no of emails to be sent and the no of > groups > $num_elements = mysql_num_rows($result); > > //figure out the total number of groups of 50 emails > $total_email_groups = floor($num_elements/50); > > //figure out the remainder of emails to send in last group > $total_remainder= $num_elements -($total_email_groups * > 50); > > > while ($rows=mysql_fetch_array($result)){ > > $name=$rows['name']; //required for individual msg > $email=$rows['email']; //get the email > > if ($x==1){ > //only need to set the below once > $subject = "Whatever my subject is"; > $message = "body of message here(can be html with > appropriate headers)"; > > //add the headers to create the html email > $headers = "MIME-Version: 1.0\n"; > $headers .= "Content-type: text/html; > charset=iso-8859-1\n"; > $headers .= "From: $your_name<$email>\nX-Mailer: > PHP Automated Mailer"; > }//end if > > //start the loop to send 50 emails at a time or last > group > if > ($x==50)||(($g==$total_email_groups)&&{$x==$total_remainder)){ > //if 50 email destinations then send > mail ($to, $subject, $message, $headers); > sleep(300); //wait 5 min to allow email > server to send out the emails > $x=1; //reset the email counter > $to=""; //reset destination > $g++; //increase the group counter > > }else{ > $to.=$email.";"; //add the email to the list > $x++; > } > > }//end while > > }//end if > > needs to be tested ">??

Provided By
Phorum