Jump to content

webstar

Members
  • Posts

    26
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

webstar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. How can i Make this code below grab the 3rd line of the file I am feeding through it and make it the subject line of the email? I'm kinda php dumb and this is likely really simple. #!/usr/bin/php <?php # E-mail recipient(s). Separate each address with a comma and a space. $emailrecip = "REMOVED"; # E-mail subject line. $emailsubject = "REMOVED"; # E-mail From name. $emailfromname = "REMOVED"; # E-mail From address. $emailfromaddr = "REMOVED"; $fp = fopen('php://stdin','r'); $data = ""; while(!feof($fp)) { $data .= fgets($fp,4096); } fclose($fp); $timestamp = "REMOVED"; $timestamp .= date("D, j M Y G:i:s O "); $timestamp .= "\n"; $timestamp .= "Emailed to you at: %EMAILSTAMP%"; $timestamp .= "\n"; # Send the e-mail. $subject = $emailsubject; $recipient = $emailrecip; $body_of_email = $timestamp; $body_of_email .= trim($data); $header = 'From: "' . $emailfromname . '" <' . $emailfromaddr . '>'; $header .= "\n"; $header .= "X-Priority: 1"; $header .= "\n"; mail ($recipient, $subject, $body_of_email, $header); echo ("E-mail sent."); ?>
  2. #!/usr/bin/php <?php # E-mail recipient(s). Separate each address with a comma and a space. $emailrecip = "removed"; # E-mail From name. $emailfromname = "removed"; # E-mail From address. $emailfromaddr = "removed"; $fp = fopen('php://stdin','r'); $data = ""; while(!feof($fp)) { $new_data = fgets($fp,4096); $data .= $new_data; $data_array[$i++]=$new_data; } fclose($fp); $patterns = array(); $patterns[0] = '/CWTO/'; $patterns[1] = '/CWWG/'; $patterns[2] = '/CWVR/'; $patterns[3] = '/CWHX/'; $patterns[4] = '/CWUL/'; $replacements = array(); $replacements[0] = '-ON-'; $replacements[1] = '-Prairies-'; $replacements[2] = '-BC-'; $replacements[3] = '-Maritimes-'; $replacements[4] = '-QC-'; $data_array = preg_replace($patterns, $replacements, $data_array); $split_line = explode(' ', $data_array[2]); $subject = $split_line[0].' '.$split_line[1].' '.trim($data_array[3]); # Send the e-mail. $recipient = $emailrecip; $body_of_email = trim($data); $header = 'From: "' . $emailfromname . '" <' . $emailfromaddr . '>'; $header .= "\n"; $header .= "X-Priority: 1"; $header .= "\n"; mail ($recipient, $subject, $body_of_email, $header); echo ("E-mail sent."); ?> I kinda went a different direction with it. The first 3 arrays work but the 4th one never seems to fire and I was wondering if anyone can tell me why.
  3. If the data from the file is already passed to the php via this $fp = fopen('php://stdin','r'); $data = ""; while(!feof($fp)) { $data .= fgets($fp,4096); } fclose($fp); would file_get_contents still work on $data?
  4. I'm trying to find the write coding to pull the First and Second words from the 2nd line and the entire 3rd line from this file and have them as $subject1 and $subject2 And I have no php background. http://www.weatherserver.net/text/CWTO/WOCN11.txt so $subject1 = WOCN11 CWTO and $subject2 = SPECIAL WEATHER STATEMENT
  5. It should be sending email IF the file on my server does not match the file being pulled OR does not exist at all on my server. But it is as if it's reading a buffer or cache from someplace else. if I delete the file on my server and try to trigger the script it runs like the file is there.
  6. This has me confused. I've posted the code here for easy reading <?php # ---------------------------------------------------------------------------------- # Configuration # Directory on the remote server. Be sure to include leading and trailing slashes! $remotedir = "/pub/data/raw/wt/"; # File on the remote server. No slashes! $remotefile = "wtnt31.knhc.tcp.at1.txt"; # Keyword to check for in response. $keyword = "$$"; # Remote server address. $remoteserver = "weather.noaa.gov"; # E-mail recipient(s). Separate each address with a comma and a space. $emailrecip = "REMOVED"; # E-mail subject line. $emailsubject = "[NHC] WTNT31 -"; # E-mail From name. $emailfromname = "REMOVED"; # E-mail From address. $emailfromaddr = "REMOVED"; $txtfilename = $remotefile; # End Configuration # ---------------------------------------------------------------------------------- # Format the page for easy viewing. Header( "Content-type: text/plain"); # Setup the request. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://" . $remoteserver . $remotedir . $remotefile); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $res = curl_exec($ch); curl_close($ch); $result = array_map('trim',explode("\n",$res)); # Check for keyword. if (!in_array($keyword,$result)) die("Weather Coding not found!"); # Read the file containing the last response. $filename = $txtfilename . '.txt'; if (file_exists($filename)) { $contents = array_map('trim',file($filename)); # Check for changes. if (count(array_diff(array_unique($contents),array_unique($result))) == 0) { # There has not been a change. echo ("No Updates\r\n"); } else { # There has been a change. echo ("**UPDATES DETECTED**\r\n"); # Write the new file. echo implode("\n",$result); file_put_contents($filename,implode("\n",$result)); $subject = $emailsubject . $result[3]; # Send the e-mail. $recipient = $emailrecip; $body_of_email = implode("\n",$result); $header = 'From: "' . $emailfromname . '" <' . $emailfromaddr . '>'; $header .= "\n"; $header .= "X-Priority: 1"; $header .= "\n"; mail ($recipient, $subject, $body_of_email, $header); echo ("E-mail sent."); } } else { # Write the new file. echo implode("\n",$result); file_put_contents($filename,implode("\n",$result)); } ?> This is what it is doing and it's confusing me. If the text on the webserver changes the script runs normally and writes to the file and emails. If I delete the .txt from my server the script SHOULD run normally and send out an email and write a new file. What it is doing is writing is skipping the email part, and jumping right to this part. else { # Write the new file. echo implode("\n",$result); file_put_contents($filename,implode("\n",$result)); } It's as if it is reading from a buffer because it's not reading from the .txt file because I deleted it but writes the txt file back to the drive. What am i missing to get it to run normally? Windows 2008 64bit R2, IIS7 and PHP FastCGI 5.1.3
  7. Thank you for your help. It works good.
  8. Wow
  9. Ok so the script above works kinda. The output to the screen is Array ( ) No Updates E-mail sent. And it does send the email the only issue is on each refresh it does it again. It isn't writing to the WTNT32.txt file so it has a record of the last email. So each refresh is a new email again.
  10. Oh wait google was my friend. Curl Support. :-p
  11. Wow, ok I wasn't expecting a rewrite but i'll take it. When I run the script it does this. <br /> <b>Fatal error</b>: Call to undefined function curl_init() in <b>C:\WEATHERSCRIPTS\NHCTest\WTNT32.php</b> on line <b>37</b><br />
  12. Please please don't fight over me, I have enough questions for everyone. *sigh* I chased everyone away.
  13. Please please don't fight over me, I have enough questions for everyone.
  14. Pretty much I am trying to use the line that is being captured as the subject rather then the current subject. <? # ---------------------------------------------------------------------------------- # Configuration # Directory on the remote server. Be sure to include leading and trailing slashes! $remotedir = "/text/station/KNHC/"; # File on the remote server. No slashes! $remotefile = "WTNT32.KNHC"; # Keyword to check for in response. $keyword = "$$"; # Remote server address. $remoteserver = "twister.sbs.ohio-state.edu"; # E-mail recipient(s). Separate each address with a comma and a space. $emailrecip = "email address"; # E-mail subject line. $emailsubject = "[NHC] WTNT32 - Public Advisory"; # E-mail From name. $emailfromname = "WxServer NHC"; # E-mail From address. $emailfromaddr = "from address"; $txtfilename = "WTNT32"; # End Configuration # ---------------------------------------------------------------------------------- # Format the page for easy viewing. Header( "Content-type: text/plain"); # Setup the request. $header .= "GET " . $remotedir . $remotefile . " HTTP/1.0\r\n"; $header .= "Host: " . $remoteserver . "\r\n"; $header .= "User-Agent: Downloader\r\n\r\n"; $fp = fsockopen ($remoteserver, 80, $errno, $errstr, 30); # Do the request. fputs ($fp, $header . $req) or die("Can't access the site!"); while (!feof($fp)) { $res .= fgets ($fp, 128); } # Strip off the header info. $headerend = strpos($res,"\r\n\r\n"); if (is_bool($res)) { $result = $res; } else { $result = substr($res,$headerend+4,strlen($res) - ($headerend+4)); } fclose ($fp); # Check for keyword. if (!strstr($result, $keyword)) die("Weather Coding not found!"); # Read the file containing the last response. $filename = $txtfilename . '.txt'; $fp = fopen($filename, "r"); $contents = fread($fp, filesize($filename)); fclose($fp); # Check for changes. if ($contents == $result) { # There has not been a change. echo ("No Updates\r\n"); } else { # There has been a change. echo ("**UPDATES DETECTED**\r\n"); # Write the new file. $filename = $txtfilename . '.txt'; $fp = fopen($filename, "w"); $write = fputs($fp, $result); fclose($fp); # Send the e-mail. $recipient = $emailrecip; $subject = $emailsubject; $body_of_email = $result; $header = 'From: "' . $emailfromname . '" <' . $emailfromaddr . '>'; $header .= "\n"; $header .= "X-Priority: 1"; $header .= "\n"; mail ($recipient, $subject, $body_of_email, $header); echo ("E-mail sent."); } ?>
  15. That not working and I think it's because the .txt file itself it just one long line rather then split up like the org. text. How hard would it be to just capture the text between "BULLETIN" and "NWS" That will just capture the line I want.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.