Here is my code
if ($action == "emailall2") {
if (!$uname) { echo "Please Login"; exit; }
if (!$from) { echo "Error: \"From\" is blank."; exit; }
if (!$subject) { echo "Error: \"Subject\" is blank."; exit; }
if (!$email) { echo "Error: \"Email\" is blank."; exit; }
$r = mysql_query("SELECT * FROM rh_clients") or die(mysql_error());
mysql_query("INSERT INTO rh_emails (reciever,sender,subject,email) VALUES ('All Clients','$from','$subject','$email')") or die(mysql_error());
while ($x = mysql_fetch_array($r)) {
$email = str_replace("\$username","$x[username]",$email);
$email = str_replace("\$name","$x[first] $s[last]",$email);
$email = str_replace("\$domain","$x[domain]",$email);
if ($x[status] == 0) {
mail("$x[email]","$subject","
$email
","From: $from");
}
}
message("Send Emails...","Emails sent.");
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=$PHP_SELF'>";
}
Now this program is to send an email to all my clients in the database. All of the values come from the page before, so you do not really have to worry about them. Also, message() is a function that I made up. This script is made so that in the message ($email) if I type in "Hello $name" all of the email will say, "Hello (and that name of that person who the email is to)" THe problem I am having is with the lines of
$email = str_replace("\$username","$x[username]",$email);
$email = str_replace("\$name","$x[first] $s[last]",$email);
$email = str_replace("\$domain","$x[domain]",$email);
No matter how many times I go through the loop, those values stay the same. That is the only problem. I want these to change to the actually values each time it goes through. The values it stays at is the first person's (who is in the database) username, name and domain. How can I fix this, thanx.