this is all the code:
<?php
session_start();
$pagefunction="admin";
$pagetitle="Mass Email";
include_once("../functions.inc");
include("../database.php");
//Begin session check
if (!isset($_SESSION['admin']['user_id'])){
header('Location:login.php');
}
$db_session=check_session($_SESSION['admin']['user_id']);
$duration=time() - $db_session;
if ($duration > $timeout){
session_unset(); #Session_unset and Session_destroy
session_destroy();#Will remove all sessions.
header("Location:login.php?code=sto");
} else {
$sqlRegUser = "UPDATE `users` SET `session` = '". time() ."' WHERE `user_id` = '". $_SESSION['admin']['user_id'] ."' LIMIT 1 ;";
mysql_query( $sqlRegUser );
}
//End session check
include_once("../header.inc");
?>
<style type="text/css">
<!--
.apDiv {
width:600px;
height:200px;
z-index:1;
overflow: scroll;
visibility: visible;
}
-->
</style>
<!--Begin body -->
<?php
$text_field_str="";
$subject_field_str="";
if (isset($_POST['function']) && $_POST['function']=="feedback") {$feedback=true;} else $feedback=false;
// get the data from db
if (isset($_POST['function'])){
if ($feedback){
//only get the students that haven't received a feedback request email yet and are subscribed to receive emails
$result = mysql_query("SELECT * FROM `students` WHERE `payer_email` IS NOT NULL AND `receive_email` = 1 AND `feedback_requested` = 0");
$subject_field_str="We want your feedback";
$text_field_str="Dear %firstname%:
At our school, customer satisfaction is our number-one priority. We take great pride in providing you with the right tools to minimize test anxiety and maximize your potential.
Please help us understand how you felt about you experience with us by participating in a brief online survey.
To access the survey click on the link below, or copy and paste the address into your browser.
http://www.site.org/survey_home.php
Thank you for your feedback and for choosing us.
_________________________________
Please do not reply to this e-mail unless you are having difficulties completing the survey. If you need further technical assistance, contact BEC at %bectechnicalemail%.
-------- IMPORTANT NOTES ---------
* We are fully committed to keeping your survey information private and secure. Please see our Online Privacy Statement to help you understand what information will be collected and how it will be used.
* If you no longer wish to receive any other communications from BEC, please click the following link to unsubscribe %becurl%unsubscribe.php?email=%studentemail%.";
} else {
$result = mysql_query("SELECT * FROM `students` WHERE `payer_email` IS NOT NULL AND `receive_email` = 1");
}
} else {
$result = mysql_query("SELECT * FROM `students` WHERE `payer_email` IS NOT NULL AND `receive_email` = 1");
}
$numRows = mysql_num_rows($result);
//set custom vars
$beccontactemail=$BEC_Email;
$bectechnicalemail="technical@site.org";
$becurl=$rootDir;
$custom_vars=array("%firstname%", "%lastname%", "%studentemail%", "%txnid%", "%beccontactemail%", "%bectechnicalemail%", "%becurl%");
if (isset($_POST['send_email'])){
//check if email not empry
$err_msg="";
$noe=0;//number of emails successfully sent
if (empty($_POST['subject'])) {
$err_msg.='The subject is empty.<br>';
}
if (empty($_POST['emailbody'])) {
$err_msg.='The email body is empty.<br>';
}
if (empty($err_msg)){
for($count = 1; $count <= $numRows; $count++){
$headers="";
$ebody=$_POST['emailbody'];
$row = mysql_fetch_array($result);
if (strpos($ebody,"%studentemail%") > 0) {
$ebody = str_replace("%studentemail%", $row['payer_email'] , $ebody);
}
if (strpos($ebody,"%firstname%") > 0) {
$ebody = str_replace("%firstname%", $row['first_name'] , $ebody);
}
if (strpos($ebody,"%lastname%") > 0) {
$ebody = str_replace("%lastname%", $row['last_name'] , $ebody);
}
if (strpos($ebody,"%beccontactemail%") > 0) {
$ebody = str_replace("%beccontactemail%", $beccontactemail , $ebody);
}
if (strpos($ebody,"%bectechnicalemail%") > 0) {
$ebody = str_replace("%bectechnicalemail%", $bectechnicalemail , $ebody);
}
if (strpos($ebody,"%becurl%") > 0) {
$ebody = str_replace("%becurl%", $becurl , $ebody);
}
if (strpos($ebody,"%txnid%") > 0) {
$ebody = str_replace("%txnid%", $row['txn_id'] , $ebody);
}
//send email
$headers .= 'To: ' . $row['first_name'] . " " . $row['last_name'] . ' <' . $row['payer_email'] . ">\r\n";
$headers .= 'From: Brooklyn Education Center <' . $beccontactemail . '>' . "\r\n";
// Mail it
if (!mail($row['payer_email'], $_POST['subject'], $ebody, $headers)){
$err_msg.="Email not sent to " . $row['payer_email'] . "<br>";
} else {
if (isset($_POST['function']) && $_POST['function']=="feedback"){
$sqlRegUser = "UPDATE `students` SET `feedback_requested` = 1 WHERE `txn_id` = '". $row['txn_id'] ."' LIMIT 1 ;";
mysql_query( $sqlRegUser );
}
$noe = $noe + 1;
}
}
}
}
if ($noe > 0) display_message("exclamation", $noe . " emails sent succesfully!");
if (!empty($err_msg)){
display_message("error", $err_msg);
}
?>
<p>Custom variables:<br>
%firstname%, %lastname%, %studentemail%, %txnid%<br>
%beccontactemail%, %bectechnicalemail%, %becurl%(includes forward slash at the end.)</p>
<form name="form" method="post" action="send_email.php">
Subject:<br />
<input name="subject" type="text" id="subject" value="<?php echo $subject_field_str; ?>" />
<br />
Body:<br />
<textarea name="emailbody" cols="70" rows="15" id="emailbody"><?php echo $text_field_str; ?></textarea>
<br>
Email will be sent to the recipients below:
<div class="apDiv">
<table width="100%" height="100%" border="0" align="left" cellpadding="0" cellspacing="3" valign="top">
<tr>
<td align="left" valign="top"><table width="100%" border="0" align="left" cellpadding="2" cellspacing="2">
<tr bgcolor="#666666">
<td width="40%" bgcolor="#666666"><b>Email</b></td>
<td width="40%" bgcolor="#666666"><b>Name</b></td>
</tr>
<?php
for($count = 1; $count <= $numRows; $count++)
{
$row = mysql_fetch_array($result);
echo '<tr bgcolor="#666666">';
echo '<td>' . $row['payer_email'] . '</td>';
echo '<td>' . $row['first_name'] . ' ' . $row['last_name'] . '</td>';
echo '</tr>';
}
?>
</table>
</table>
</div>
<?php
if ($feedback) echo '<input name="function" type="hidden" value="feedback">';
?>
<input name="send_email" type="submit" value="Send Email" id="send_email">
</form>
<!--End body -->
<?php
include("../footer.inc");
?>