Jim Lucas wrote:
Payne wrote:
Jim Lucas wrote:
So, to summarize everything said, with my own added notes.

[EMAIL PROTECTED] wrote:
Hi,

I am currently working on a php script that will be called by cron. But I
have an error that keeps coming up.

Parse error: syntax error, unexpected T_VARIABLE inmail_report.php on

What I am trying to do is a simple php script to send me a report
everynight. Any clues as to why? Also does anyone know of a site with mail
srcipts that are ran on the cli?

---------------------------------------------
<?php


The following wont work if you use this from the CLI. There is not remote addr.
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

//This is a simple email to give me the status from yesterday.
//This connect the script to the db
require_once('mysql_connect.inc');


Loose the semi-colon at the end of your SELECT statements. The mysql extension for PHP will add it on its own.

$query = "Select ip, date, time, CONCAT(city, ', ',country) as location
from ips where country !=' ' and date = current_date() order by
date,time,country asc;";

You missed a semi-colon at the end of this line
$result = mysql_query($query)

        $mailsend = mail("[EMAIL PROTECTED]","The IP's that Attacked
$hostname", "The following are ip's that have try to attack your
system.\r\n\r\



You can't do this within a function call. Like someone else said, you need to run the if/else and while portion before you mail call. Capture that data and then add it to the mail call.

        if ($result) { //if that ran ok, display the record
echo "<table width=\'150\'><tr><td> Country </td><td> # of
Attacks
</td></tr>";

                //fetch and print the records

                while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
                echo "<tr><td align=\'left\'>$row[0]</td><td><div
align=\'right\'>$row[1]</div></td></tr>";
                }

                echo '</table>';

                mysql_free_result ($result); //free up the resources

                } else {  //if did not run ok

echo '<p>This could not be display due to a system error.
We apologize
fore any incovenience.</p><p>'. mysql_error() . '</p>';

                }

","From:[EMAIL PROTECTED] To:[EMAIL PROTECTED]");
print("$mailsend");
?>





So here is the code re factored.

<?php

# Setup your variables for later use.
$recipient     = '[EMAIL PROTECTED]';
$subject       = 'The IP\'s that Attacked';
$add_headers[] = 'From: [EMAIL PROTECTED]';
$add_headers[] = 'Reply To: [EMAIL PROTECTED]';
$separator     = "\r\n";

//This is a simple email to give me the status from yesterday.
//This connect the script to the db
require_once('mysql_connect.inc');

$query = "
SELECT   ip,
         date,
         time,
         CONCAT(city, ', ',country) as location
FROM     ips
WHERE    country != ''
  AND    date = current_date()
ORDER BY date, time, country asc
";

$result = mysql_query($query);

ob_start();
echo <<<TXT
The following are ip's that have try to attack your system.

TXT;

//if that ran ok, display the record
if ($result) {
  echo <<<TABLE

<table width='150'><tr><td>Country</td><td># of Attacks</td></tr>
TABLE;

  //fetch and print the records
  while ( $row = mysql_fetch_assoc($result) ) {
    echo <<<ROW
<tr>
  <td align='left'>{$row['ip']}</td>
  <td><div align='right'>[$row['date']}</div></td>
</tr>
ROW;
  }

echo '</table>';

//free up the resources
mysql_free_result ($result);

} else {
  //if did not run ok
  echo '<p>This could not be display due to a system error.
We apologize for any incovenience.</p><p>'. mysql_error() . '</p>';

}

$body = ob_get_clean();

$mailsend = mail($recipient, $subject, $body, join($separator, $add_headers));

print($mailsend);

?>

Jim,

thanks, well I am still trying to work it out. Your scripts gives me this when I run it....

------------------------------------------------------------------

[EMAIL PROTECTED]
to me
  show details 9:02 PM
    Reply
    Reply To: [EMAIL PROTECTED]

The following are ip's that have try to attack your system.

<table width='150'><tr><td>Country</td><td># of Attacks</td></tr></table>


----------------------------------------

And mine is doing this now....e-mails the html code and nothing from the db....


<html>
<head>
    <title>Attack's on $hostname</title>
</head>
<body>
       if ($result) { //if that ran ok, display the record
echo "<table width='150'><tr><td> Country </td><td> # of Attacks </td></tr>";
                            //fetch and print the records
while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr><td align='left'>$row[0]</td><td><div align='right'>$row[1]</div></td></tr>";
               }
                            echo "</table>";
mysql_free_result ($result); //free up the resources
                            } else {  //if did not run ok
echo "<p>This could not be display due to a system error. We apologize fore any incovenience.</p><p>". mysql_error() . "</p>";
                            }
mysql_close(); //Close the database connection.
</body>
</html>

--------------------------------------------------

Here is my update code....

<?php
     2 //VAR Are set here....
     3

This is much better then before.
     4 $hostname = `hostname -f`;
     5
     6 //This is a simple email to give me the status from yester day.
     7 //This connect the script to the db
     8
     9 //To use ',' between e-mail address for multiple recipents
    10 $to = '[EMAIL PROTECTED]';
    11
    12
    13 //Set the Subject here...
    14 $subject = "The IPs that Attacked $hostname report from Fyre";
    15
    16 //Database Set is here...
    17 require_once('mysql_connect.inc');
    18
19 $query = "Select ip, date, time, CONCAT(city, ', ',country) as location from ips where country !=' ' and date = current_date() order by date,time,country asc;";
    20 $result = mysql_query($query) ;
    21
    22 //The Message goes here....


Are you really trying to put the PHP code that you want in the email body like you would the source code for a script, or are you wanting the output of the php(db results) in the following sections to be included in the contents of the email?
    23 $message = '
    24 <html>
    25 <head>
    26      <title>Attack\'s on $hostname</title>
    27 </head>
    28 <body>

If you answered that you want the results of the db set in the email, do this instead.

End the previous $message = ' thing on the end of line that has <body>

so <body>';

Then follow along below to get the results in the email.

    29         if ($result) { //if that ran ok, display the record


Change this to $message .= '     instead of echo
30 echo "<table width=\'150\'><tr><td> Country </td><td> # of Attacks </td></tr>"; 31 32 //fetch and print the records 33 34 while ($row = mysql_fetch_array($result, MYSQL_NUM)) {


Change this to $message .= '     instead of echo
35 echo "<tr><td align=\'left\'>$row[0]</td><td><div align=\'right\'>$row[1]</div></td></tr>";
    36                 }


Change this to $message .= '     instead of echo
    37                    38                 echo "</table>";
39 40 mysql_free_result ($result); //free up the resources 41 42 } else { //if did not run ok


Change this to $message .= '     instead of echo
43 44 echo "<p>This could not be display due to a system error. We apologize fore any incovenience.</p><p>". mysql_error() . "</p>";
    45                    46                 }
47 48 mysql_close(); //Close the database connection.

Then close it all with this:

$message .= '
    49 </body>
    50 </html>
    51 ';
    52

Now, if you echo $message here you should see all the results and you should be in business.

FYI: If you are wanting HTML embedded in your email for display purposes, then you will need to make sure you are sending the correct headers for the client to see HTML and render it properly.

    53

Personally, I would move all the headers stuff to the top of the script.
    54 //To Sent HTML Mail; The Content-type header must be set
    55 $headers = 'MIME-Version: 1.0' . "\r\n";
56 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

You are killing your other headers here by not having the .= syntax
    57 $headers = 'From: FYRE REPORT <[EMAIL PROTECTED]>';
    58
    59 // Mail it
    60 mail($to, $subject, $message, $headers);
    61
    62 ?>
    63


Let me know what happens.

Jim Lucas

Jim,

Thanks. I am getting what I want...The only thing and I will work it out is the table doesn't come thru as you can see....Again thanks.

The IPs that Attacked magi.magidesign.com report from Fyre
Friday, July 25, 2008 6:23 AM
From FYRE REPORT Fri Jul 25 03:23:27 2008
Return-Path:         <[EMAIL PROTECTED]>
To:         [EMAIL PROTECTED]
Subject:         The IPs that Attacked magi.magidesign.com report from Fyre
MIME-Version:         1.0
Content-type:         text/html; charset=iso-8859-1
From: FYRE REPORT <[EMAIL PROTECTED]> Add sender to Contacts
Message-Id:         <[EMAIL PROTECTED]>
Date:         Fri, 25 Jul 2008 06:23:27 -0400 (EDT)
Content-Length:         277107
Compact Headers

The following ip\s where caught by Fyre

ip *    date    time    location $
12.96.210.11    2008-07-22    21:50:05    Towson, MD, UNITED STATES
60.28.26.148    2008-07-22    06:30:39    Tianjin, CHINA
202.168.255.226 2008-07-22 06:30:07 Overland Park, KS, UNITED STATES
211.21.185.251    2008-07-22    06:40:22    Unknown City, TAIWAN
222.126.145.236    2008-07-23    16:12:32    Unknown City, Unknown Country
209.242.168.228    2008-07-23    22:10:58    San Diego, CA, UNITED STATES
59.106.14.41    2008-07-23    07:30:08    Fukuoka, JAPAN
66.8.54.166    2008-07-23    14:30:50    Johannesburg, SOUTH AFRICA
213.171.255.2    2008-07-23    08:40:09    Madrid, SPAIN



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to