Jump to content

Recommended Posts

Here is a simple one.

[code]
<?php
include("db.php"); // your database connection file
$subject = "Some Subject";
$headers = "FROM: you@yoursite.com";
$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

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.