所以我正在开发一个脚本,最终将作为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;
?>
有什么建议吗?
答案 0 :(得分: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);
答案 1 :(得分: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;