J'essaie d'envoyer plusieurs courriels dans tandis que la boucle, avec le code suivant, il n'envoie pas de notification par courrier électronique et de donner des erreurs "Erreur fatale": Erreur non capturée: Classe "phpmailer" introuvable dans c:\xampp\htdocs\clinique\paients\run_medications. PHP: 98 Trace de pile: # 0 {Main} jeté dans '. Bien que l'emplacement soit correct et son envoi unique d'un courrier électronique d'un autre répertoire enfant.
require_once('../includes/PHPMailer.php');
require_once('../includes/SMTP.php');
require_once('../includes/Exception.php');
$full_dt = date('Y-m-d H:i:s');
$dt = date('Y-m-d');
$dt_hr = date('H');
$check_timing = $con->prepare("SELECT medication, start_time, end_time FROM timings WHERE HOUR(end_time) = :end ");
$check_timing->bindparam(':end', $dt_hr);
$check_timing->execute();
$count1 = $check_timing->rowCount();
if($count1 > 0) {
while($rows = $check_timing->fetch(PDO:: FETCH_OBJ)) {
$medication = $rows->medication;
$start_time = $dt.' '. $rows->start_time;
$end_time = $dt.' '.$rows->end_time;
$timestamp = strtotime($end_time) + 60*60;
$end_hour = date('Y-m-d H:i:s', $timestamp);
$query = "SELECT a.location_code, b.* FROM patients a INNER JOIN medication b ON a.id = b.pat_id WHERE b.status != 2 AND b.directions = :med AND b.last_time NOT BETWEEN :start AND :end AND :crntime BETWEEN b.start_date AND b.end_date AND :crntime BETWEEN :end AND :end_hour";
$statement = $con->prepare($query);
$statement->bindparam(':med', $medication);
$statement->bindparam(':start', $start_time);
$statement->bindparam(':end', $end_time);
$statement->bindparam(':crntime', $full_dt);
$statement->bindparam(':end_hour', $end_hour);
$statement->execute();
$count = $statement->rowCount();
if($count > 0) {
while($row = $statement->fetch(PDO:: FETCH_OBJ)) {
$drug_id = $row->drgid;
$code = $row->location_code;
$pat_id = $row->pat_id;
$drug = $row->med_type.' - '.$row->drug.' ('.$row->strength.')';
$dose = $row->dosage;
$route = $row->route;
$directions = $row->directions;
$getUserName = "SELECT name FROM users WHERE FIND_IN_SET(location_code, :codes)>0 ";
$runUser = $con->prepare($getUserName);
$runUser->bindParam(':codes',$code);
$runUser->execute();
$check = $runUser->rowCount();
if($check > 0) {
$userRow = $runUser->fetch(PDO::FETCH_OBJ);
$by = $userRow->name;
}
$insert_report = $con->prepare("
INSERT INTO `report` (`med_id`,`pat_id`,`dtime`,`responsible`,`status`) values(:m_id,:p_id,:time,:by,'3')");
$insert_report->bindparam(':m_id',$drug_id);
$insert_report->bindparam(':p_id',$pat_id);
$insert_report->bindparam(':time',$end_time);
$insert_report->bindparam(':by',$by);
$insert_report->execute();
$mail = new PHPMailer();
$mail->isSMTP();
$mail-> SMTPOptions = array (
'ssl' => array (
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = "587";
$mail->Username = "[email protected]";
$mail->Password = "12345678";
$mail->Subject = "Medication Report";
$mail->setFrom("[email protected]",$by);
$mail->isHTML(true);
//Attachment
//$mail->addAttachment('img/attachment.png');
//Email body
$mail->Body = "<h3>Medication Report by ($by) </h3></br>
You are being alerted that <b>$name</b> has missed their $directions Medication $row->med_type. And you may need to take appropriate action..";
$mail->addAddress($to_email['Email_add']);
$mail->send();
} // /while
}// if num_rows
}//while close
}// if num_rows
Vous avez dans votre code:
$check = $runUser->rowCount();
if($check > 0) {
$userRow = $runUser->fetch(PDO::FETCH_OBJ);
$by = $userRow->name;
}
$insert_report = $con->prepare("
INSERT INTO `report` (`med_id`,`pat_id`,`dtime`,`responsible`,`status`) values(:m_id,:p_id,:time,:by,'3')");
$insert_report->bindparam(':m_id',$drug_id);
$insert_report->bindparam(':p_id',$pat_id);
$insert_report->bindparam(':time',$end_time);
$insert_report->bindparam(':by',$by);
Mais si aucune ligne n'est retournée et $check
est donc 0, variable $by
n'aura pas été défini. Mais vous continuez ensuite avec votre logique à utiliser $by
Pour l'insertion de la base de données et pour envoyer un email. Je penserais que cela pourrait éventuellement générer une exception de base de données si la colonne responsible
n'est pas nullable. Dans tous les cas, il s'agit clairement d'une logique incorrecte.
Vous avez également beaucoup de tests pour le nombre de lignes retournées avant d'exécuter vos boucles while
. Ces tests sont vraiment redondants: si le nombre de lignes retournées est 0, la boucle while
_ _ La boucle quitte immédiatement si vous ne faites que tester la déclaration de récupération FALSE
. Donc, le niveau de nidification peut être réduit en éliminant ces contrôles redondants.
Le deuxième problème est que votre colonne de lecture name
à partir de table -tilisateurs et le stocker en variable $by
. Pourtant, le corps de votre message électronique références variables $name
, qui n'a pas été définie. J'ai provisoirement remplacé cela avec Varibale $by
. Mais seulement vous pouvez dire si cela est correct ou non. Mais clairement sinon, alors vous devez initialiser $name
avec sa valeur appropriée.
$full_dt = date('Y-m-d H:i:s');
$dt = date('Y-m-d');
$dt_hr = date('H');
$check_timing = $con->prepare("SELECT medication, start_time, end_time FROM timings WHERE HOUR(end_time) = :end ");
$check_timing->bindparam(':end', $dt_hr);
$check_timing->execute();
while(($timingRow = $check_timing->fetch(PDO:: FETCH_OBJ)) !== FALSE) {
$medication = $timingRow->medication;
$start_time = $dt.' '. $timingRow->start_time;
$end_time = $dt.' '.$timingRow->end_time;
$timestamp = strtotime($end_time) + 60*60;
$end_hour = date('Y-m-d H:i:s', $timestamp);
$query = "SELECT a.location_code, b.* FROM patients a INNER JOIN medication b ON a.id = b.pat_id
WHERE b.status != 2 AND b.directions = :med AND b.last_time NOT BETWEEN :start AND :end
AND :crntime BETWEEN b.start_date AND b.end_date AND :crntime BETWEEN :end AND :end_hour";
$statement = $con->prepare($query);
$statement->bindparam(':med', $medication);
$statement->bindparam(':start', $start_time);
$statement->bindparam(':end', $end_time);
$statement->bindparam(':crntime', $full_dt);
$statement->bindparam(':end_hour', $end_hour);
$statement->execute();
while(($row = $statement->fetch(PDO:: FETCH_OBJ)) !== FALSE) {
$drug_id = $row->drgid;
$code = $row->location_code;
$pat_id = $row->pat_id;
$drug = $row->med_type.' - '.$row->drug.' ('.$row->strength.')';
$dose = $row->dosage;
$route = $row->route;
$directions = $row->directions;
$getUserName = "SELECT name FROM users WHERE FIND_IN_SET(location_code, :codes)>0 ";
$runUser = $con->prepare($getUserName);
$runUser->bindParam(':codes',$code);
$runUser->execute();
$userRow = $runUser->fetch(PDO::FETCH_OBJ);
if ($userRow !== FALSE) {
$by = $userRow->name;
$insert_report = $con->prepare("
INSERT INTO `report` (`med_id`,`pat_id`,`dtime`,`responsible`,`status`) values(:m_id,:p_id,:time,:by,'3')"
);
$insert_report->bindparam(':m_id',$drug_id);
$insert_report->bindparam(':p_id',$pat_id);
$insert_report->bindparam(':time',$end_time);
$insert_report->bindparam(':by',$by);
$insert_report->execute();
$mail = new PHPMailer();
$mail->isSMTP();
$mail-> SMTPOptions = array (
'ssl' => array (
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = "587";
$mail->Username = "[email protected]";
$mail->Password = "12345678";
$mail->Subject = "Medication Report";
$mail->setFrom("[email protected]",$by);
$mail->isHTML(true);
//Attachment
//$mail->addAttachment('img/attachment.png');
//Email body
$mail->Body = "<h3>Medication Report by ($by) </h3></br>
You are being alerted that <b>$by</b> has missed their $directions Medication $row->med_type. And you may need to take appropriate action..";
$mail->addAddress($to_email['Email_add']);
$mail->send();
}
} // while($row = ...
} //while $timingRow = ...