Jump to content

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: 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.";


?>

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

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.