Hello hope someone can help me out, I am trying to send out emails to users that owns servers, with date limits. So far i am able to send mail individually with the code i have below but i am unable to send the body with all the servers that individual owns.
For example, I keep getting email that only show 1 host name when there is suppose to be 2, thanks all for your help!
Here is the code i have so far, feel free to make recommendations, since i am very new to all this.
<?php
$que = mysql_query("SELECT Email,PrimaryContact,Hostname FROM sm_table WHERE NewSetDate='2011-07-01' ORDER BY Hostname ASC");
$res = mysql_query("SELECT DISTINCT Email FROM sm_table WHERE NewSetDate='2011-07-01' ORDER BY Hostname ASC");
$sql = mysql_query("SELECT DISTINCT Hostname FROM sm_table WHERE NewSetDate='2011-07-01' GROUP BY Hostname ASC");
$pc = 'PrimaryContact';
$hc = 'Hostname';
$em = 'Email';
//while($row = mysql_fetch_assoc($que)or die(mysql_error())) {
//echo 'Primary Contact: ' . $row[$pc] . '<br/>' . 'Hostname: ' .
$row[$hc] . '<br/>'. 'Email: ' . $row[$em] . '<br/> <br/>';
while($row2 = mysql_fetch_array($sql) or die(mysql_error())) {
//$hostlist[] = $row2['Hostname'];
//print_r ($hostlist);
//print $row['Hostname'];
$body = "List of Servers:";
$body .= $row2['Hostname'];
$body .="\nPlease click on link to register or cancel";
$subject = "Server Registration";
$from = "emialerts@partners.org";
$headers = "From:" . $from;
if ($row1 = mysql_fetch_assoc($res)or die(mysql_error())) {
$to = $row1[$em];
mail($to,$subject,$body,$headers);
}
}
?>
I would like to be able to send to each owner there servers they own. I so far am able to send to multiple user but not able to attach their server list on the body of the email. it sends it one at a time and or sends it twice , example
hostname email primarycontact
abc 123@hello.com joe smith
zzz 123@hello.com joe smith
ggg lily@yahoo.com lily smith
hhh lilly@yahoo.com lilly smith
jjj lilly@yahoo.com lily smith
in the above example joe smith should only get 1 email with 2 hostname, abc and zzz
same for lily smith 1 email with 3 hostname hhh jjj and ggg. CAN YOU PLEASE HELP AND THANKS EVERYONE!
phpme1221
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jun 29, 2011 12:57 pm