<?php
session_start();
error_reporting(E_ALL);
include ('db.php');
require 'PHPMailer/PHPMailerAutoload.php';
function cron_cirugias1(){
$start1 = date("d/m/Y");
$start = strtotime($start1);
$end = strtotime("+30 days", $start);
$datediff = $end - $start;
$datediff = floor($datediff/(60*60*24));
for($i = 0; $i < $datediff + 1; $i++){
$db=new Database;
$q2=$db->query("SELECT * FROM cirugias WHERE fecha='".date("d/m/Y", strtotime($start . ' + ' . $i . 'day'))."' ORDER BY STR_TO_DATE(fecha,'%d/%m/%Y') ASC");
$r2=mysqli_fetch_array($q2);
if(mysqli_num_rows($q2)>0){
$qdr=$db->query("SELECT * FROM usuarios WHERE id='".$r2['id_usuario']."'");
$rdr=mysqli_fetch_array($qdr);
##
$resultado .= '<tr class="gradeA">
<td>'.$r2['nombre'].'</td>
<td>'.$r2['observaciones'].'</td>
<td>'.$rdr['nombredr'].'</td>
<td>'.$r2['telefono'].'</td>
<td class="center">'.date("d/m/Y", strtotime($start . ' + ' . $i . 'day')).'</td>
<td class="center">'.$r2['hora'].' - '.$nuevaHora.'</td>
<td class="center">'.strtoupper($r2['tipo1']).' - '.$r2['tipo2'].'<br><font color="red">'.$r2['diopt'].'</font></td>
<td class="center">'.$r2['lente'].'</td>
</tr>';
}
}
$cuerpo='
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<!-- Dynamic table -->
<div class="table">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Paciente</th>
<th>Observaciones</th>
<th>Dr(a)</th>
<th>Teléfono</th>
<th>Fecha</th>
<th>Hora</th>
<th>Tipo</th>
<th>Lente</th>
</tr>
</thead>
<tbody>
'.$resultado.'
</tbody>
</table>
</div>
</body>
</html>
';
$mail = new PHPMailer;
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noresponder@domain'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('noresponder@domain', 'Sistema Cron');
$mail->addAddress('luis@domain', '');
$mail->CharSet = 'UTF-8';
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Respaldo de la Agenda (Cirugías)';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->MsgHTML($cuerpo);
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
// RUN
cron_cirugias1();
function cron_estudios1(){
$start1 = date("d/m/Y");
$start = strtotime($start1);
$end = strtotime("+30 days", $start);
$datediff = $end - $start;
$datediff = floor($datediff/(60*60*24));
for($i = 0; $i < $datediff + 1; $i++){
$db=new Database;
$q2=$db->query("SELECT * FROM estudios WHERE fecha='".date("d/m/Y", strtotime($start . ' + ' . $i . 'day'))."' ORDER BY STR_TO_DATE(fecha,'%d/%m/%Y') ASC");
$r2=mysqli_fetch_array($q2);
if(mysqli_num_rows($q2)>0){
$qdr=$db->query("SELECT * FROM usuarios WHERE id='".$r2['id_usuario']."'");
$rdr=mysqli_fetch_array($qdr);
##
$resultado.= '<tr class="gradeA">
<td>'.$r2['nombre'].'</td>
<td>'.$r2['observaciones'].'</td>
<td>'.$rdr['nombredr'].'</td>
<td>'.$r2['telefono'].'</td>
<td class="center">'.date("d/m/Y", strtotime($start . ' + ' . $i . 'day')).'</td>
<td class="center">'.$r2['hora'].' - '.$nuevaHora.'</td>
<td class="center">'.strtoupper($r2['tipo1']).' - '.$r2['tipo2'].'</td>
</tr>';
##
}
}
$cuerpo = '
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<div class="table">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example1">
<thead>
<tr>
<th>Paciente</th>
<th>Observaciones</th>
<th>Dr(a)</th>
<th>Teléfono</th>
<th>Fecha</th>
<th>Hora</th>
<th>Tipo</th>
</tr>
</thead>
<tbody>
'.$resultado.'
</tbody>
</table>
</div>
</body>
</html>';
$mail = new PHPMailer;
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noresponder@domain'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('noresponder@domain', 'Sistema Cron');
$mail->addAddress('luis@domain', '');
$mail->CharSet = 'UTF-8';
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Respaldo de la Agenda (Estudios)';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->MsgHTML($cuerpo);
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
// RUN
cron_estudios1();
?>
升级mysql 5.6后出现问题。在此之前,我的代码运行就像一个魅力。现在,我得到了这个: 注意:未定义的变量 信息已发送 注意:未定义的变量 消息已发送
这两封邮件都已发送,但变量$ resultado为空。 有人能给我一个解决这个问题的线索吗?
保佑