im new to php and i need a bit of clarification. ive searched google but tooo many results, none clearly identify whats wrong with mine. since i dont get any errors im not sure whats happening.
the error im getting is this:
Warning: mail() expects parameter 1 to be string, array given in
so longstory short, this is a small bit of my code:
while( $sn_rowSelect = mysqli_fetch_array($sn_queryResult) ) {
mail($to,$subject,$mssg,'from:xyz');
}
if(mail($to,$subject,$mssg,'from:xyz')) {
echo "An e-mail was sent to $to with the subject: $subject";
} else {
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid";
}
what im trying to do is, i have a small database with names etc, with this loop above, its suppose to say that while theres a name in $sn_rowSelect, to feed it the message, essentially emailing the whole lot of emails.
the error says “expects string, array given’ im assuming means the name gotten from the DB is gotten as an assosiative array value, but, isnt that what its supposed to do?
thanks in advance.
EDIT***
$to = $sn_rowSelect;
$from = $_POST['sender'];
$mssg = $_POST['message'];
from and mssg, are filled out via a form on another page.
You must set the $to parameter inside the while loop, and you need to set it to a string. You will also need to move the
ifstatement inside the while loop if you want it to make sense, and you can’t call mail() twice since that will create redundant emails.Here’s a fixed code for you: