So, to summarize everything said, with my own added notes. payne@xxxxxxxxxxxxxxxxxxx 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("terrorpup@xxxxxxxxx","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:fyre@xxxxxxxxxxxx\r\nReply To:fyre@xxxxxxxxxxxx"); print("$mailsend"); ?>
So here is the code re factored. <?php # Setup your variables for later use. $recipient = 'terrorpup@xxxxxxxxx'; $subject = 'The IP\'s that Attacked'; $add_headers[] = 'From: fyre@xxxxxxxxxxxx'; $add_headers[] = 'Reply To: fyre@xxxxxxxxxxxx'; $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 Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php