Jump to content

How to send multiple emails from mysql using php ?


alinpion

Recommended Posts

I want to send multiple emails (the emails are stored in a mysql database) using a php code; here is what I got so far:

 

<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db_name", $con);

/*code for sending multiple emails*/
/*what I need is a code that that takes all the emails from a table from a database and put's them in a array something like this: [email protected] ; [email protected] ; etc. and the sequence below must be adapted so it can use this array for sending multiple email ; it will be good that the below sequence after it sends 5 mails to wait 5 seconds and then resume the mail sending process (this is for avoiding server block) */


$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";


?>

So you want to send the same mail to multiple contacts, am I right?

 

I would use a while(), looking something like this:

$recipient = "";
while($row = mysql_fetch_array("SELECT blabla FROM blabla")){
     $recipient .= $row['email'];
     $recipient .= "; ";
}

 

I think that should work...

Hi! You can store the required data (i.e. email id, message, subject etc)  at your mysql DB table. For storing you can use serialized method to make it more promising.  Finally you can send mail though PHP normal mail function or SMTP fetching the data from your DB through loop. You can code for a little while break after every looping. This thing will be helpful to send mail successfully.

Hope this guide line will be helpful to you.

 

Cheers!!!

 

-----------------------------------------

Source: http://ScriptsTurbo.com

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.