Cant get this script to work. Please help.
<html>
<head>
<title></title>
</head>
<body>
<?php
$username = "my name";
$password = "my password";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db("mydb",$dbh)
or die("Could not select mydb");
$result = mysql_query("SELECT email FROM news");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo $row{'email'}.",<br>";
}
$maillist = array($row{'email'});
echo $maillist;
foreach($maillist as $maillist) {
mail("$maillist","subject","Content");
}
mysql_close($dbh);
?>
</body
I was able to make an array like this:
<?php
$maillist = array('myemail@nowhere.com', 'amotheremail@somewhere.com', 'youremail@nowhere.com');
foreach($maillist as $maillist) {
mail("$maillist","subject","Content");
}
?>
which works fine but cant get it to work with the database. Please help.