0
<?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();
?>

The problem is present after upgrade mysql 5.6. Before this, my code was running like a charm. Now, I got this: Notice: Undefined variable Message has been sent Notice: Undefined variable Message has been sent

Both mails are sent but with variable $resultado empty. Can somebody give me a clue to solve this?

Bless

Luis Lara
  • 27
  • 1
  • 8
  • The PHP error should have provided a line number. Please update your question and include the line number for the errors. Also, in your code please mark those lines number with a comment. – MonkeyZeus Jun 07 '16 at 19:48
  • Way way waaaaay too much code. Narrow it down to the actual problem code. – Jonnix Jun 07 '16 at 19:48
  • `Undefined variable Message has been sent` means you're doing something silly like `$foo = 'Message has been sent'; $$foo`. upgrading mysql is NOT going to cause php syntax errors. – Marc B Jun 07 '16 at 19:50
  • Also, which variable is it saying is undefined? – Jonnix Jun 07 '16 at 19:50
  • It is very likely that this problem has always existed but errors were being suppressed. Since you upgraded to PHP 5.6, the `php.ini` is probably set to show errors. – MonkeyZeus Jun 07 '16 at 19:53

0 Answers0