I’ve read & tried a few posts but can’t get this problem solved. I’m trying to send mail to addresses in a database, but get the following error: Warning: mail() expects parameter 3 to be string, array given …
include 'datalogin.php';
$sql10 = "SELECT * FROM ex_usrs_admin_dept WHERE linked_dept = '$newdept1'";
$res10 = mysql_query($sql10);
while ($row10 = mysql_fetch_assoc($res10)) {
$adminid1 = $row10['adminid'];
$elist = mysql_query("SELECT mail_address FROM ex_usrs WHERE id = '$adminid1'");
$subject = "This is the subject";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$message = '<h3>This is the message</h3>';
ini_set(SMTP, "10.xxx.xxx.xx");
ini_set(smtp_port, 25);
ini_set('display_errors', '1');
ini_set("sendmail_from", "xx@xx.com");
if (mysql_num_rows($elist) > 0) {
while ($elist_result = mysql_fetch_array($elist)) {
$headers = array('To' => $elist_result['mail_address']);
mail($subject, $message, $headers);
}
}
}
You have mixed up the parameters of the mail function … your should be sending the following :
Note the
$tofield at the start. Change your while loop fromto
The PHP documentation is very detailed