Jump to content

mailing list


fullyloaded

Recommended Posts

Here is a simple one.

[code]
<?php
include("db.php"); // your database connection file
$subject = "Some Subject";
$headers = "FROM: [email protected]";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative;\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit";
$headers .= "\r\n";

$sql = mysql_query("SELECT * FROM `yourtable`") or die(mysql_error());
$i = 0;
while ($rw = mysql_fetch_assoc($sql)) {
    if ($i = 20) {
        sleep(1);
        $i = 0;
    }
     $message = 'Hello ' . $rw['username'] . ',
      This is a test mass mail.';
     $to = $rw['email'];
     mail($to, $subject, $message, $headers);
     $i++;
}
mysql_free_result($sql);
?>
[/code]

Hope this helps,
Tom
Link to comment
https://forums.phpfreaks.com/topic/20465-mailing-list/#findComment-90203
Share on other sites

  • 1 year later...
Sorry for bring up such an old post, but I guess this is what happens when you use the search function.  :P

The script above works perfectly for me to be able to send a message to each person in my database to alert them when I have updated their points BUT ONLY if I write a single line message like in the example above.

I have been trying to get multiple lines to work, but everything I try breaks the loop. The first user in the database gets the notification, and it formats perfectly, but no further emails are sent.

This the code I tried to add:

[code]$message = "Hello, \n\n";
$message .="The quiz results have been processed! \n\n";
$message .="Please visit http://domain.com/ to see how you fared against everyone else. \n\n";
$message .="Admin \n\n";[/code]

I have tried single quotes as well. Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/20465-mailing-list/#findComment-449727
Share on other sites

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.