getNumSensors(); $sensors = []; for ($i = 0; $i < $num; ++$i) { $id = $digitemp->getSensorId($i); $rrdtemp->addSensor($id); $sensors[] = $rrdtemp->readLastData($id); } $upper = $config['mail_alert_upper']; $lower = $config['mail_alert_lower']; $do_send = false; foreach ($sensors as $sensor) { if ($sensor['latest'] < $lower || $sensor['latest'] > $upper) { $do_send = true; break; } } if ($do_send) { $from = $config['mail_from']; $from_name = $config['mail_from_name']; $to = $config['mail_alert_to']; $subject = $config['mail_alert_subject']; $loader = new \Twig\Loader\FilesystemLoader(APPDIR.'/'.$config['templates_dir']); $twig = new \Twig\Environment($loader); $data = [ 'range' => [ 'upper' => $upper, 'lower' => $lower, ], 'sensors' => $sensors, 'from' => [ 'name' => $from_name, 'email' => $from, ], 'url' => $config['url'], ]; $body = $twig->render($config['mail_alert_template'], $data); $from = new \Orrisroot\Mail\Address($from_name, $from); $tos = [new \Orrisroot\Mail\Address($to, $to)]; \Orrisroot\Mail\UTF8_Mailer::sendMail($from, $tos, $subject, $body); }