/ Published in: PHP
                    
                                        
In light of last nights tornado warnings here in TN, I thought it appropriate to post this little bit of code that I use to alert myself and others of dangerous weather conditions via SMS/Email alerts.
I run this through cron at Dreamhost without issues.
                I run this through cron at Dreamhost without issues.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?php
$timeout = 5; // set to zero for no timeout
$db = new SQLiteDatabase('noaa.db2');
/*
$time = time();
$db->query("BEGIN;
CREATE TABLE status ( id INTEGER PRIMARY KEY, timestamp );
INSERT INTO status (timestamp) VALUES($time);
COMMIT;");
*/
$result = $db->query('SELECT * FROM status WHERE id = 1 LIMIT 1',SQLITE_ASSOC); //SQLITE_NUM SQLITE_BOTH (Default)
//echo $data['timestamp'];
$xml = new SimpleXMLElement($contents);
foreach($xml->channel->item as $item) {
require("phpmailer/class.phpmailer.php"); //http://sourceforge.net/projects/phpmailer
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "xxxx"; // SMTP username
$mail->Password = "xxxx"; // SMTP password
$mail->FromName = "John Self";
//$mail->AddAddress("[email protected]"); // Add as many recipients as you want
$mail->IsHTML(false);
$mail->Subject = "WEATHER ALERT";
$mail->Body = "A TORNADO WARNING HAS BEEN ISSUED FOR DAVIDSON COUNTY";
$mail->AltBody = "A TORNADO WARNING HAS BEEN ISSUED FOR DAVIDSON COUNTY";
if(!$mail->Send())
{
echo "Message could not be sent.
";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
exit;
}
}
}
}
?>
Comments
 Subscribe to comments
                    Subscribe to comments
                
                