Hello all,
I am newbie trying to write a script that retrieves email addresses and sends an email. I am having a problem with the current row assignment when I attempt to run the code with PHP 5. What am I doing wrong with the lines bolded below to assign the current row values to variables? I currently get an undefined assignment. All Help is apprecaited.
Cheers
/ Date : Sept. 12, 2006 /
/ /
/ Purpose -> PHP script to query faculty table for instructors who have not /
/ completed official rosters and then send an email to remind them./
/ declare relevant variables /
$DBhost = "";
$DBuser = "";
$DBpass = "";
$DBName = "";
$table = "courses";
/ Connect to MySql server/
$link = mysqli_connect(
$DBhost,
$DBuser,
$DBpass,
$DBName);
/ check connection /
if (!$link){
printf ("Can not connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$query = "select distinct courses.cou_Pidm,
instructors.inst_Email,
instructors.inst_First_Name,
instructors.inst_Last_Name
from officalroster.courses, officalroster.instructors
where courses.cou_Status='' and
courses.cou_term='200710' and
courses.cou_Session='1' and
instructors.inst_Email = 'omar36' and
instructors.pidm= courses.cou_Pidm";
/Select queries return a resultset /
$result = mysqli_query($link, $query);
$row_cnt = mysqli_num_rows($result);
if ($row_cnt < 1) {
echo "There Were No Results for Your Search";
}
else {
//primer read
$row = mysqli_fetch_array($result);
while (!is_null($row)){
/Interation of the mail function /
$instEmail = $row["instructors.inst_Email"];
$instFirstName = $row["instructors.inst_First_Name"];
$instLastName = $row["instructors.inst_Last_Name"];
echo $instEmail;
echo $instFirstName;
$to = $instEmail . '@';
$subject = 'Official Roster Reminder';
$message ='
<html>
<head>
Hello <B>$instFirstName $instLastName</B>,\n\n
Just a friendly reminder that the deadline for submitting Official Class Rosters for Fall 2006\n
is <B>Friday, October 6 2006 at 10p.m.</B> Please login to the following website:
<A href=""> http://</A>\n
and complete your rosters. To log into the application please use your email username\n
and password. If you have any questions, please contact the Office of Admissions at \n
\n
Thank You.
\n
The Office of Admissions and Records
</body>
</html>
';
$message = wordwrap($message, 70);
$headers = 'From: [email][/email]' . "\r\n" .
'Reply-To: [email][/email]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//Mail it
mail ($to, $subject, $message, $headers);
echo $to;
echo $subject;
echo $message;
echo $headers;
$row = mysqli_fetch_array($result);
}/end while /
mysqli_close($link);
}
?>