NWS Public Alert Messenger PHP Script

Is anybody interested in a log file feature for this script?
It could append to a log file every time there is an alert.
You could include the log file in a Advisory History page.

I was thinking something like this:





Mike,

I think a log would be really cool. Would it be a running log that showed the last “X” number of alerts or something like all alerts for a week, or month, etc. and was self maintaining?

Derek

It should be self maintaining or the log would grow continuously.
Maybe it could auto purge oldest alerts after x amount of alerts are built up.
The x amount of alerts to store could be a setting that can be changed.
Also the logging feature can be enabled or disabled with a setting.

Does this sound good?
I might not do this for a few days, I have programmed so many hours this week I feel tired.
Right now, I am working on two computers at once, and writing a seminar: Internet and Computer Safety - “How to stay clear of viruses, adware, spyware, spam, and scams when using the Internet”.

Got it - thanks, Mike. I figured as much. I will just adjust the timing in the script accordingly as our local NWS oftentimes sends out three or four short term forecasts in a row, each spanning a couple of hours.

As for a log file, that might be kind of nice. Ideally it would be like you say where it gets overwritten after a period of time.

T

Mike,

I think all that sounds great.

I don’t doubt you’re tired, with what you’ve done here over the last few days alone, not to mention all the other stuff you’re doing. We all really appreciate everything but for sure you should take a break!!!

Derek

Here is a good question!

Using the script i took notice that if you are with a hosting company with the emails going out it never goes out with the correct email information. Sample say you place in the script $email_address_sent_from = ‘[email protected]’;

So when the message comes down it shows it is from [email protected]
Now they had me edit my php.ini files to have this:
sendmail_path = /usr/sbin/sendmail -t -i -f [email protected];

And it still with go back to [email protected]. Now one thing they said that would correct that problem is if the script used SMTP Authentication This way the email that is generated by the script would have the correct sent from email address as in [email protected].

Is there an easy way of adding that?

What host is causing all this trouble? is it windows or Linux?

First, just try this code in the settings section of the script after the $email_address_sent_from:

ini_set('sendmail_from', $email_address_sent_from); // needed for some windows servers

if that did not work, try adding this:


// OPTIONAL: You can change the default SMTP settings below...
// NOTE most servers do not need these settings changed!!!
$ctf_ini_set       = "yes";        // "yes" to enable this feature (ONLY if needed)
$ctf_smtp          = "localhost"; // sometimes mail.yourdomain.com Confirm with your host
$ctf_smtp_port     = "25";        // Confirm with your host
$ctf_smtp_username = "you";       // your mail username. If you do not know, ask your host
$ctf_smtp_password = "123456";    // your mail password. If you do not know, ask your host
$ctf_sendmail_from = "[email protected]";   // Your email
$ctf_sendmail_path = "/usr/sbin/sendmail -t -i"; // If different, ask host


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);
}
    

let me know if it worked.

they are all Linux box’s. going to try this one in this location in the script:

<?php error_reporting(E_ALL ^ E_NOTICE); // Report all errors except E_NOTICE warnings ini_set('display_errors', 1); // turn error reporting on //ini_set('log_errors', 1); // log errors //ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); // where to log errors /* NOAA Top Weather Advisory Alerter PHP Script by Mike Challis More Info - www.642weather.com/weather/scripts-noaa-top-weather-alerter.php Download - www.642weather.com/weather/scripts/noaa-top-weather-alerter.zip Live Demo - www.642weather.com/weather/rss-weather-alerter.php Free PHP Scripts - www.642weather.com/weather/scripts.php Contact Mike - www.642weather.com/weather/contact_us.php Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2319642 // Mail Settings // OPTIONAL: You can change the default SMTP settings below... // NOTE most servers do not need these settings changed!!! $ctf_ini_set = "yes"; // "yes" to enable this feature (ONLY if needed) $ctf_smtp = "localhost"; // sometimes mail.yourdomain.com Confirm with your host $ctf_smtp_port = "25"; // Confirm with your host $ctf_smtp_username = "you"; // your mail username. If you do not know, ask your host $ctf_smtp_password = "123456"; // your mail password. If you do not know, ask your host $ctf_sendmail_from = "[email protected]"; // Your email $ctf_sendmail_path = "/usr/sbin/sendmail -t -i"; // If different, ask host 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); }

The above didn’t work.

That is not a good location in the script to put PHP code because that is a comment section. PHP code there is ignored.

Put it just before this:

//------------------------------------------------------------------
// end settings. Do not alter any code below this point in the script or it may not run properly.
//------------------------------------------------------------------

Just got off the phone with tech support, since i have the directory set to 600 i needed it set to 700 for owner read write and excute. also in my php.ini had spaces in there. did a test after they told me this email address seems to be working now. Helps if there are no spaces when i am editing a php.ini file huh? lol.

So now i have the directory hidden again with the correct chmod on it. so have to wait till it sends the forecast down in a few hours to see what it says, since there are no warnings that script will not do anything unless i out it in test mode. but letting the cron job run to see if the other works. if one does the other should.

Well i will check my email on my cell tomorrow if still doing the same will test it with it down there.
will let ya know!
thanks.

You can test it right now with this setting:

// set to 1 to test the script's email function (it will send a test fake alert, be sure to set it back when done)
// set to 0 for normal operation
$test_email_advisory = 1;

set it to 1, load the script in a url, check email.
set it back to zero after you test.

Erice emailed me back saying they disabled safe_mode for me. But Im still getting an error with that txt file. Should I remove that file now and see If it works without it? Thanks.

http://www.snoqualmieweather.com/rss-weather-alerter.php

Ahh… I’m going to take a gander next week @ the coding and maybe ill see if its possible to add some quick “hey the storm will be here at xx time” or something. Basically something super quick but has a little more detail perhaps? Does the NOAA use specific format for the alert text?

Yea it works fine that way without the email script. but when it runs from the crontab that is when it gives the other email address by default. So this morning from the crontab running got the defalt email address once again.

So i added that snip for the email part into the script where you showed to add it. so waiting for it to resend the message again. Won’t happen till about 2pm est.

will let you know if that worked.

Well after putting that into the script, the cronjob ran and same thing gives me that default address. Will have to get support on the phone to find out why it is always defaulting to that address and not the one that i have set for it.

I had some oddities with running scripts from cron using the command line PHP. I was getting error emails about some PHP component that was missing. My server host tech support is sometimes not very fast, so I found another way to call my script using cron and CURL and it solved the problem. I wonder if you tried the CURL method would the email work properly?

PHP method:
php /path/to/nws-forecast-messenger.php 2>&1 > /dev/null

Curl method:
/usr/bin/curl NWS Weather Forecast Messenger PHP Script by Mike Challis >/dev/null 2>&1

Thanks for your help Mike, The test email to my phone worked perfect.

Has visitors every asked if you were able to send out email alerts like this, and would you do it? Not sure though If many people like to give out there email address like that though.

Just got back home will be checking with support, as i have that directory only available to owner access only, Will try the curl next. they did point me to a help file here is that it says about php and email:

Problem:

Why do e-mails from my webpage come from < username > @ < host# > .domain.com when I have specified otherwise?
Solution:

This is because our servers require you (or your script) to use a properly formatted, valid From: header in your email.

If the From: header is not formatted correctly, empty or the email address doesn’t exist on our server, the from address will be changed to @.domain.com.

To stop this, you must change the script you are using to correctly use a valid From header.

Examples of headers that should work would be:
From: [email protected]
From:
From: “name”

Examples of headers that will NOT work:
From: “[email protected]
From: user @ domain.com

Alternative for PHP Users:

  • You can also modify which account should be used when sending out using the mail() function. Inside the local php.ini file, you will find a line of code that looks something like this (around line 601):

sendmail_from = [email protected]

Be sure to uncomment this by deleting the ‘;’ before the directive. Also, the account you use must be a valid created account.

Now i did set the sendmail in the format it says in the php.ini.

Giess u have to call them back again.