I want to create a script that will send an email every time the dynamic ip of my site changes. I have followed the following steps to install php mail options:
apt-get install php-pear
pear install mail
pear install Net_SMTP
pear install Auth_SASL
pear install mail_mime
apt-get install postfix
I have a script that reports the ip address when ever it's ran, but I only want it to send a message when the ip address changes. The code for reporting my public ip address is as follows:
<?php
$to = "me@example.com";
$subject = "Routers ip address";
$body = exec("curl -s
http://whatsmyip.net/ |grep -i '<title>' | cut -d : -f$
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
I have tried a few thing to get this to work, but no luck. I would like this script to only send a message when the ip address changes if possible:
/* DOES NOT WORK */
<?php
$body = exec("curl -s
http://whisismyip.net/ |grep -i '<title>' | cut -d : -f 2 | sed 's!</title>!!'");
$ip = "/home/user/Documents/currentip";
/*currenip is a file with the current ip address in it! */
if ($body != $ip) {
$to = "user@example.com"
$subject = "Public ip address";
$body = exec("curl -s
http://whisismyip.net/ |grep -i '<title>' | cut -d : -f 2 | sed 's!</title>!!'");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
This last script doesn't work!! I've tried! Please help, you're my only hope!
edit: also it doesn't send mail!