Hello,
i hope to find out some mistake i´m doing with one application using PHP and MySQL to send site news to users on the database table (FirstName, LastName and Email), by the 'mail' function.
Here follows the script i developed, but it´s not completly working and i need help.
<?php
$conexion = mysql_connect("host","user","pass");
if ($conexion){
mysql_select_db("db_clients");
$query = mysql_query("SELECT FirstName, LastName, Email FROM clients");
if ($query) {
$n = mysql_affected_rows();
$subject = "Email title";
$mesage = "Trying to use news via PHP";
$headers = "MIME-Version: 1.0\n";
$headers .= "text/plain charset=iso-8859-1\n";
$headers .= "From: Me <me@mydomani.com>\n";
while ($list = mysql_fetch_array($query, MYSQL_NUM)){
// Here i put the query result at one array
// in format "FirstName LastName <Email>"
$recipients[] = $list[0] . " " . $list[1] . " <" . $list[2] . ">";
}
for ($i=0; $i < $n; $i++){
// That´s the thing. Here i want to send the
// mail message, but its not sending.
// Its allways going to 'else' statment.
if (mail($recipients[$i], $subject, $mesage, $headers))
echo ("Mail send to : $recipients[$i]");
else echo ("Not sent to $recipients[$i]");
}
}
else {
echo ("Query error!");
}
}
else echo("MySQL error" . mysql_error());
mysql_free_result($query);
mysql_close($conexion);
?>