note 54928 deleted from function.mail by bjori
| From: | bjori@php.net | Date: | Tue, 05 Sep 2006 08:54:17 +0000 |
| Subject: | note 54928 deleted from function.mail by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116683@lists.php.net to get a copy of this message | ||
Note Submitter: Guido
----
When you want to sent mail to emailadresses that you've got stored in a database, one can use
this code (at least it's been usefull to me ;):
// fetch adresses from database
while ($emailadresses = mysql_fetch_array($query, MYSQL_ASSOC)) {
foreach ($emailadresses as $oneMailadres) {
$recepients .= "$oneMailadres"; //build up the recepient string
$recepients = $recepients . ", ";
}
}
// this is the tricky part: mail() will not sent to all the emailadresses, if you let your string
end with ', ', so I used substr() to remove the last two characters from the string (comma
and space).
$recepients = substr($recepients, 0, -2);
//actual sending
mail($recepients, $subject, $mailbody, "From: $senderAddress");