0

所以我正在开发一个脚本,它最终将作为 shell 运行,通过比较当前的 ip 来检测 ip 地址的变化(

//get_ip.php
<?php
$current_ip = file_get_contents('http://www.ipaddresscheck.comlu.com/ip.php');
?>

)

(如果有人感兴趣,http://www.ipaddresscheck.comlu.com/ip.php 将只返回您的机器/路由器的公共 IP)

到mysql中记录的最新一条。现在,我什至无法通过电子邮件发送虚假的旧 IP 和真实的当前 IP。当我尝试通过电子邮件发送新旧 IP 时,它只会起作用,我将旧 ip 变量放在当前位置或根本没有。它应该说

The old IP adresss was --- ".$old_ip."
The new IP address is  --- ".$current_ip."

但这行不通。唯一有效的是

The old IP adresss was --- ".$old_ip."
The new IP address is  --- ".$old_ip."

或者

The old IP adresss was --- ".$old_ip."
The new IP address is  --- 


<?php
//Get IP
include 'get_ip.php';
//Connect to SQL
mysql_connect('localhost','root','root');
//Select database
mysql_select_db("ip_changes") or die(mysql_error());
//Get Date Info
$date = date("D M Y");
$time = date("H i s");
//Generate SQL query
$sql="INSERT INTO ip (date, time, current_ip)
VALUES ('$date', '$time', '$current_ip')";
//Execute SQL
mysql_query($sql);
//$sqlcurrent = mysql_query(SELECT current_ip FROM ip ORDER BY id DESC LIMIT 1);
echo $current_ip;
$new_ip = $current_ip;
//Send Mail
$old_ip = '192.168.0.1';
$to = "justinmarmorato@gmail.com";
$subject = "IP Address Change";
$message = "Hello! This is an automated message from the IPMS.  An IP address chamge has been 
detected.
//Right here, I can only send out $old_ip, and nothing else.  The date and time at the bottom does work.
The old IP adresss was --- ".$old_ip."
The new IP address is  --- ".$old_ip."
The IP address change was detected at ---". $date. ' , '. $time;
$message1 = 'Old IP:'.$old_ip.
'New IP:'.$current_ip;
$from = "no-reply@http://mar-remote-net.dns2.us";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo 'Old IP:'.$old_ip.
'New IP:'.$current_ip;
?>

有什么建议么?

4

2 回答 2

0

毫无疑问,它不起作用,因为您使用了错误的变量名:

$message = "Hello! ...";
//why is it called message1?
$message1 = 'Old IP:'.$old_ip. 'New IP:'.$current_ip;

//here you are sending $message
mail($to,$subject,$message,$headers);
于 2013-06-26T06:00:40.783 回答
0

我想到了...

$finalmessage = <<< EOT
    Hello! This is an automated message from the IPMS. An IP address change has been detected.
    <html>
    <style>
    table, th, td
    {
    border: 2px solid black;
    border-color:grey;
    }
        </style>
    <table class='table'>
    <tr>
    <td>Old IP</td><td>New IP</td><td>Time Detected</td>
    </tr>
    <tr>
    <td>$old_ip</td><td>$new_ip</td><td>$date  $time</td>
    </tr>
    </table>
    </html>
EOT;
于 2013-06-27T14:45:32.550 回答