Once again I am having problems and cannot figure out why becuase I wrote this script from another I had, the only differnce is that I am trying to bcc email addresses out of a field in my database called student_email:
<?php
// This script adds a students and all their information into the database so
//admins and teachers can access, update, and change the information as needed
// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
//Setup the datbase connection
include("../include/config.php");
include("../include/opendb.php");
include("../include/functions.php");
// Execute the query.
$email_title = trim($_POST['title']);
$email_text = trim($_POST['email_text']);
// Check if the form has been submitted.
if (isset($_POST['submit']))
{
$problem = FALSE; // No problems so far.
if (empty ($email_title)) //check to see if Title has been entered
{
$problem = TRUE;
echo '<p>You forgot to enter the title of the email, Please hit the back button and fill in the missing information</p>';
echo "<input type=button value=\"Back\" onClick=\"history.go(-1)\">";
exit;
}
if (empty ($email_text)) //check to see if Email Body has been entered
{
$problem = TRUE;
echo '<p>You forgot to enter the email text, Please hit the back button and fill in the missing information</p>';
echo "<input type=button value=\"Back\" onClick=\"history.go(-1)\">";
exit;
}
if (!$problem) //If there is no problem then we will send a message to all parents
{
// From
$mailFrom = 'Little SOS';
$mailFromName = 'admin@littlesaints.net';
$mailTo = 'Mike.Simonds@dalsemi.com';
// Reply address
$mailReplyTo = $mailFrom;
// Message subject and contents
$mailSubject = $email_title;
$mailMessage = $email_text;
// Text message charset
//$mailCharset = "windows-1252"; // must be accurate (e.g. "Windows - 1252" is invalid)
// Create headres for mail() function
//$headers = "Content-type: text/html; charset=$mailCharset\r\n";
$headers = "From: $mailFromName <$mailFrom>\r\n";
$headers .= "Reply-To: $mailReplyTo\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "X-Priority: 1";
$query = 'SELECT student_email FROM students';
// Define mysql info here
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
while ($row = mysql_fetch_object($result))
{
echo $row->student_email;
$email = $row['student_email'];
echo $headers .= "Bcc: $email\n";
}
// Send mail
mail($mailTo, $mailSubject, $mailMessage, $headers);
}
}
?>
here is the form:
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Email title: <input type="text" name="title" size="40" maxsize="100" /></p>
<p>Email Text: <textarea name="email_text" columns="40" rows="5"></textarea></p>
<input type="submit" name="submit" value="Send Email To Parents" />
</form>
it sends the email to the $mailTo but not the bcc users
Thanks in advance!
Mike