alinpion Posted November 25, 2010 Share Posted November 25, 2010 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: smith@yahoo.com ; mary@yahoo.com ; 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 = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> Quote Link to comment Share on other sites More sharing options...
arbitter Posted November 27, 2010 Share Posted November 27, 2010 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... Quote Link to comment Share on other sites More sharing options...
stevephp Posted December 3, 2010 Share Posted December 3, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.