RE: [PHP] Help Needed with MySQL Query
| From: | Don Read | Date: | Fri, 18 Apr 2003 18:41:11 +0000 |
| Subject: | RE: [PHP] Help Needed with MySQL Query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144428@lists.php.net to get a copy of this message | ||
On 18-Apr-2003 Pushpinder Singh Garcha wrote:
> Hello All,
>
>
> I am trying to send email to some people depending on the outcome of a
> query. Here is a code snippet. This snippet is part of the code that
> will be run daily to check the validity of Login Names on the basis of
> number of days that are left in their cycle.
>
> After getting the list of email addresses in form of an array
> $email_list, I try to explode the list with an aim of sending a mail to
> each contact. For some reason, there is a error in the last part of the
> code and hence email is not sent to the contacts.
>
> // START OF PHP-CODE
>
> $string4 = "SELECT e_mail from test where
priv_level = 0
> AND
> informed = 'NULL' ";
> $result4 = mysql_query($string4)
> or die (mysql_error());
>
> $num_rows4 = mysql_num_rows($result4);
>
> if($num_rows4 !=0){
> echo "NUM_ROWS_4<br>";
> while ($qry1 = mysql_fetch_array($result4)){
> $list1 .= $qry1['e_mail']."\n";
> }
> }
>
>
> echo "This is the list: <br>".$list1."<br>";
> // echo "Count of this list is : ".count($list1);
>
>
>
> $body = "Please note that your login has expired and you will no
> longer be able to use the MasterStream ";
> $body .= "Website. Please contact your CMI to get a new Passport
> Number and use that to login to the site";
> $body .= "Many Thanks";
> $body .= "Admin";
>
>
> $subject2 = "Notification of Passport Expiration";
> $msg2 = $body;
> $mailheaders2 = "From: MasterStream Administrator\n";
> $mailheaders2 .= "Reply-To: $email_return \n\n";
>
> $email_list = explode(" ", $list1);
> echo "COUNT IS NOW == ".count($email_list)."<br>";
Ugh! Why are you bulding a string then exloding ? how about:
unset($email_list);
while ($qry1 = mysql_fetch_array($result4)){
$email_list[] = $qry1['e_mail'];
}
...
foreach($email_list as $em) {
$res=mail($em, ...);
echo '<BR> ', $em, ' mail ', (($res) ? 'sent' :
'failed');
}
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.