//code has been updated to only send email if the ip has changed. no more full mailboxes.
//you must enable read and write permission on the ipcheck.txt file
$url = 'http://checkip.dyndns.org/';
$raw = file_get_contents($url);
//$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
//$content = str_replace($newlines, "", html_entity_decode($raw));
//$start = strpos($content,'^');
//$end = strpos($content,'?',$start) + 8;
//$ip = substr($content,$start,$end-$start);
echo "{$raw}"; //this is the external ip you can pop in anywhere.
//echo "{$ip}";
$myFile = "ipcheck.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 1000);
fclose($fh);
if ($raw == $theData) { die; }
else { $fw = fopen($myFile, "w");
fwrite ($fw, $raw);
fclose ($fw);
include("phpmailer/class.phpmailer.php");
//ini_set("include_path", ".:/var/www/phpmailer/");
//require("class.phpmailer.php");
//require("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "ssl";
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "YOURPASSWORD"; // SMTP password
$mail->Port = 465;
$mail->From = "[email protected]";
$mail->FromName = "YOURNAME";
$mail->AddAddress("[email protected]", "villain");
//$mail->AddAddress("[email protected]"); // name is optional
$mail->AddReplyTo("[email protected]", "Information");
$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "ip update";
$mail->Body = "{$raw}";
$mail->AltBody = "({$raw})";
//$mail->Body = "{$ip}";
//$mail->AltBody = "({$ip})";
if(!$mail->Send())
{
echo "Message could not be sent. ";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "
";
echo "Message has been sent";
}}
//echo $myFile; for testing.
//echo $raw;
//echo $theData;
?>