Jump to content

How to use php to send multiple emails at a time


Ashmit

Recommended Posts

Hello,

 

I am new in PHP and I want a script for sending  multiple emails using the php and i am calling that email address from database.I also want to change the status field from database from No to Yes once I send the particular emails. How to do that? I need a urgent help

 

Following is my code for calling the email address

<?

mysql_connect("localhost","root","123") or die(mysql_error()); // my database connection

mysql_select_db("localacct") or die(mysql_error());

 

$sql = "SELECT email FROM company where status='No'";

 

 

$res = mysql_query($sql) or die(mysql_error());

 

 

while($row = mysql_fetch_assoc($res) )

{

$area .= $row['email']. ", "; 

 

}

// read the list of emails from the file.

$email_list = explode(',', $area);

 

// count how many emails there are.

$total_emails = count($email_list);

 

  // go through the list and trim off the newline character.

for ($counter=0; $counter<$total_emails; $counter++)

{

$email_list[$counter] = trim($email_list[$counter]);

}

 

$to = $email_list;

 

//echo $to;

$t0 = "";

$subject = "Test email";

$message = wordwrap($message, 100);

$from = "my email address";

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= "From: $from";

mail($to,$subject,$message,$headers);

if ($count % 10 == 0) {

    sleep(5); // this will wait 5 secs every 10 emails sent, and then continue the while loop

    }

    $count++;

}

?>

 

Many Thanks in advance.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.