Hi,
I've installed a simple email collection form on my website which writes new email records onto a text file on my server. It works great but I would like to receive an email notification every time a new email address is collected. I'm far from being an expert so could someone help me add the relevant code to the write.php file? That would be much appreciated. Thanks a lot. Below is the current code.
<?php
$enable_cookies = ($_GET['c'] == "1");
$file = "emails.txt";
$email = $_GET['e'];
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest"){
$email_list = file_exists("emails.txt") ? explode(",", file_get_contents("emails.txt")) : array();
array_pop($email_list);
if(!in_array($email, $email_list)){
if(file_put_contents($file, $email.",", FILE_APPEND)){
echo "<font color='#ffffff' face='Arial, Helvetica, sans-serif' size='-1'> Added ".stripslashes(htmlspecialchars($email)) ." to the list!</font>";
if(substr(sprintf('%o', fileperms('emails.txt')), -4) != "0640"){
chmod("emails.txt", 0640);
}
if($enable_cookies){
setcookie("em_email", $email, time()*2, "/");
}
}
else{
echo "<font color='ffffff' face='Arial, Helvetica, sans-serif' size='-1'>Failed to add to list!</font>";
}
}
else{
echo "<font color='ffffff' face='Arial, Helvetica, sans-serif' size='-1'>Email already in the list!</font>";
}
}
else{
echo "This script can only be accessed through javascript!";
}
?>