Uutiset:

Ei uusia uutisia.

Main Menu

Email-ilmoitus WD:n kaatumisesta

Aloittaja HapaK, lauantai, 09.10.2010, 21:20

« edellinen - seuraava »

0 Jäsenet ja 1 Vieras katselee tätä aihetta.

HapaK

Mitenkäs saisi generoitua sähköpostiin ilmoituksen WD:n kaatumisesta? Katkos datassa voi tietty johtua myös nettiyhteyden pätkimisestä - kiitos Elisan - mutta jos ei tiettyyn aikaan dataa päivity, postilaatikkoon voisi kolahtaa varoitus.

weatherc

Tämän voi periaatteessa tehdä monella tapaa mutta tässä yksi:

- sinulla sivut webhotellissa (esim. Suncomet) jolla mahdollisuus ajaa cronjobbeja (ajastettuja tehtäviä)
- Pienellä php-skriptillä tarkistat x väliajoin clientraw.txt:n tuoreuden ja jos on vanhempi kun y sekuntia php lähettää sinulle postin laatikkoon.

Tämä versio on siitä hyvä että se ei ole riippuvainen kotoisan wx-purkin yhteydestä vaan raksuttaa websivun palvelimella.
Tässä pätkää, ei mitenkään testattua, kaappasin sen siitä mun status-sivulta:  ;D

<?php
// email address the form emails to
 
$mail_to 'aaa@yyy.net';
 
// Page-email, just needed as sender
 
$email "bbb@vvv.net";
 
 
// Site Name / Title
 
$sitename 'Sääasema Halikko';

 
// Site Domain without the http://www like this: $domain = 'proweatherstore.com';
 // can be a single domain:      $domain = 'proweatherstore.com';
 // can be an array of domains:  $domain = array('proweatherstore.com','someothersite.com');
 
$domain 'nordicweather.net';

 
// wordwrap email message text so lines are no longer than 70 characters.
 // SET  $wrap_message = 1;  ON,  $wrap_message = 0; for OFF.
 
$wrap_message 1;

 
// Content-language for email message header
 
$ctf_language 'en-us';

 
// Charset for email message header
 
$ctf_charset 'iso-8859-1';

 
// Content-transfer-encoding for email message header
 
$ctf_encoding 'quoted-printable';
 
 
// Subject & message sent if files are old
 
$subj "Testmessage";
 
$msg "This is a testmessage";

$clientraw '/full/path/to/clientraw.txt';
// How many seconds to wait before message are sent
$offset '600';

$crtime filemtime($clientraw);
$diff time() - $crtime;

if(
$diff $offset) {
      
// wordwrap email message
      
if ($wrap_message) {
         
$msg wordwrap($msg70);
      }

      
// prepare the email header
      
$header =  "From: $sitename <$email>" PHP_EOL;
      
$header .= "Reply-To: $emailPHP_EOL;
      
$header .= "Return-Path: $emailPHP_EOL;
      
$header .= 'MIME-Version: 1.0' PHP_EOL;
      
$header .= 'Content-type: text/plain; Content-language: '.$ctf_language.'; charset="'.$ctf_charset.'"' PHP_EOL;
      
$header .= 'Content-transfer-encoding: '.$ctf_encoding PHP_EOL;

      
// send the email
      
if(strtolower($ctf_ini_set) == "yes") {
       
ini_set("SMTP"$ctf_smtp);
       
ini_set("smtp_port"$ctf_smtp_port);
       
ini_set("smtp_password"$ctf_smtp_password);
       
ini_set("smtp_username"$ctf_smtp_username);
       
ini_set("sendmail_from"$ctf_sendmail_from);
       
ini_set("sendmail_path"$ctf_sendmail_path);
      }
      
ini_set('sendmail_from'$email); // needed for some windows servers
      
mail($mail_to,$subj,$msg,$header);
      
ini_restore('sendmail_from');     // needed for some windows servers
}
?>