Jump to content

[SOLVED] Including a list of records in an email


86Stang

Recommended Posts

I need to include the list of members that are about to be purged in an email that will be mailed to a manager.  This will be put into a daily cronjob.  I've got it all figured out with the exception of displaying the members in the email.

 

<?php

// time settings.
$time = time() - (60*60*72); // change the last digit to the number of hours in the past you want to range to.

$query = mysql_query("SELECT * FROM table WHERE join_date >" . $time);

$number = mysql_num_rows($query);

// display all deleted members
while($row = mysql_fetch_array($query)) {
echo $row['username'] . "<br />";
}


// mail settings
$to = "[email protected]";
$subject = "Automated removal of pending members";
$message = "This is an automated message letting you know that the server has removed $number pending members that are 72 hours old or older that never activated their account.";
$from = "[email protected]";
$headers = "From: $from";

// mail it out!
mail($to,$subject,$message,$headers);

?>

 

How do I stuff the names of the members that I looped into $message?  Am I doing it wrong by looping?  Should it be an array maybe?  Any help would be greatly appreciated!

try this

while($row = mysql_fetch_array($query)) {
  $members.=$row['username']. "\r\n";
}

then this

$to = "[email protected]";
$subject = "Automated removal of pending members";
$message = "This is an automated message letting you know that the server has removed $number pending members that are 72 hours old or older that never activated their account."\r\n".$member;
$from = "[email protected]";
$headers = "From: $from";

You had $members in the first snippet and $member in the second but outside of that it worked like a charm!

 

Now, so I can take something from this -- what is the point of the . after $members here:

 

$members.=$row['username']. "\r\n";

 

Since this is a loop, I'm guessing it's saying "add the incoming username to the $members variable" (?)

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.