I am trying to use a script to send a list of items from a database. The code is listed below. I get an unexpected T_IF error on the second $mailer->Body line (line 55). If I comment out the 9 $mailer->Body lines with php code (55-62 and 64), the script works correctly.
I am relatively new to coding, so I am sure I have left something out, I just do not know what. Any help would be appreciated.
I am relatively new to coding, so I am sure I have left something out, I just do not know what. Any help would be appreciated.
Code:
?php require_once('Connections/jma.php'); ?>
<?php require_once("Connections/dbConnection.php"); ?>
<?php
$date = date('Y-m-d');
$days_to_add = 7;
$dateArray = explode("-",$date);
$startTimestamp = mktime(0,0,0,$dateArray[1],$dateArray[2],$dateArray[0]);
$endTimestamp = mktime(23,59,0,$dateArray[1],$dateArray[2]+$days_to_add,$dateArray[0]);
// Create SQL to read in database records
$sql = "SELECT id,title,body, UNIX_TIMESTAMP(dateField) AS timestampField ";
$sql .= "FROM calendardata ";
$sql .= "WHERE UNIX_TIMESTAMP(dateField) >= " . $startTimestamp . " AND UNIX_TIMESTAMP(dateField) <= " . $endTimestamp . " ";
$sql .= "ORDER BY UNIX_TIMESTAMP(dateField) ASC";
// Open Database Connection
$dbLink = mysql_connect($dbHost, $dbUser, $dbPass);
if (!$dbLink){
die ("Database: Couldn`t connect to mySQL Server");
}
mysql_select_db($dbName, $dbLink)
or die ("Database: Couldn`t open Database");
// Read in Records from Database
$dbResult = mysql_query($sql, $dbLink)
or die ("MySQL Error: " . mysql_error() );
$numRecords = mysql_num_rows($dbResult);
for($i=0;$i < $numRecords;$i++){
$temp = mysql_fetch_assoc($dbResult);
if (!get_magic_quotes_gpc()) {
$temp['title'] = stripslashes($temp['title']);
$temp['body'] = stripslashes($temp['body']);
}
$records[] = $temp;
}
// Close Database Connection
mysql_close($dbLink);
?>
<?php
// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
// instantiate the class
$mailer = new FreakMailer();
// Set the subject
$mailer->Subject = 'This is a test';
// Body
$mailer->Body = '<p>This is a list of all events (field trips, guest speakers, assemblies, etc) occurring at John Milledge in the next seven days. Any events that will affect the normal school day should be listed here. If you know of an event that should be listed, please email the event to <a href=\"mailto:lstephens@johnmilledge.org\">Linda Stephens</a>. Please keep in mind that all of these events do not appear on the John Milledge website.</p><p><br> ';
$mailer->Body .= if ($numRecords <> 0) { ;
$mailer->Body .= foreach($records as $record);
$mailer->Body .= { $time=date("h:i a", $record['timestampField']) ;
$mailer->Body .= if ($time=="12:00 pm"){ echo date("l m-d", $record['timestampField'])} ;
$mailer->Body .= else {echo date("l m-d h:i a", $record['timestampField'])} echo $record['title'] ;
$mailer->Body .= if($record['title']==$record['body']) {""};
$mailer->Body .= else { echo $record['body']} . '</p><hr> ' . } } ;
$mailer->Body .= if ($numRecords == 0) { ;
$mailer->Body .= '</p> There are no events planned in the next seven days.';
$mailer->Body .= };
$mailer->isHTML(true);
// Add an address to send to.
$mailer->AddAddress('keley@johnmilledge.org', 'Kendall Eley');
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
else
{
echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
?>
Comment