Jump to content

PHP mail multiple email addresses. Please help!


mcerveni

Recommended Posts

I'm trying to send multiple emails from $row['email']. When i run the script, none of the echo statements show.

It also doesn't email anything.

 

 

Code shown below:

 


<?php 

if( $dbc = @mysql_connect('localhost','user', 'pass') ){
      //connect to myblog database
      if( !@mysql_select_db ('stats') ){
         $diestring = '<p> Could not select the database because: <b>'
         .mysql_error().'</b> </p>';
         die ($diestring);
        }
    } else {
       $diestring = '<p> Could not connect to MySQL because: <b>'
       .mysql_error().'</b> </p>';
      die($diestring);
   }
}


$sql = "SELECT * FROM stats.employee_compo LEFT JOIN stats.sched ON employee_compo.EmpID = sched.empID ";
$result = mysql_query($sql) or die(mysql_error());
$row= mysql_fetch_array($result);


$agentName = $row['agentName'];
$sunday = $row['sunday'];
$monday = $row['monday'];
$tuesday = $row['tuesday'];
$wednesday = $row['wednesday'];
$thursday = $row['thursday']; 
$friday = $row['friday'];
$saturday = $row['saturday'];


foreach($result as $row) { 
    echo $row['email'].",";

$to = $row['email']; 
$subject = "Your New Scheduale"; 
$body = " $agentName, <br><br>

Your new scheduale is shown below:  <br><br>

<table style='border:1px solid black; text-align:center' >
<tr><th> Sunday </th>  <th> Monday </th>  <th>Tuesday </th>  <th> Wednesday </th>  <th> Thursday</th>  <th> Friday </th>  <th> Saturday </th> </tr>
<tr> <td>  $sunday  </td>  <td>  $monday </td>  <td>  $tuesday  </td>  <td>  $wednesday  </td>  <td>  $thursday  </td>  
<td>  $friday </td>  <td>  $saturday  </td>  </tr>
</table>

"; 


if (mail($to, $subject, $body)) { 
  echo("<p>Scheduales have been sent!</p>"); 
} else { 
  echo("<p>Message delivery failed...</p>"); 
} 
} 


?>

I'm not going to write a tutorial on using databases with php here as there are many already on the net. Without trying to sound harsh though, your code is pretty messed up.

 

There is a link in my signature to a book called Hudzilla. It has an entire chapter dedicated to the subject, I would suggest you take a look there.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.