Codice PHP:
<?php
/** Hi, please change line 9 with your email address */
?>
<?php
/** NOTE: Be sure to change the name of the txt file to something more secure and update it below, if you change name, also renames subscribers.txt file.*/
$subscribersList = "subscribers.txt";
/** enter your email address. You will receive a notification email when a user subscribes to your list*/
$adminEmail = "hakim93@hotmail.it";
/** do not edit anything below unless you know what you're doing*/
function GetField($input) {
$input=strip_tags($input);
$input=str_replace("<","<",$input);
$input=str_replace(">",">",$input);
$input=str_replace("#","%23",$input);
$input=str_replace("'","`",$input);
$input=str_replace(";","%3B",$input);
$input=str_replace("script","",$input);
$input=str_replace("%3c","",$input);
$input=str_replace("%3e","",$input);
$input=trim($input);
return $input;
}
/**E-mail Validation*/
function validEmail($emailtext)
{
$isValid = true;
$atIndex = strrpos($emailtext, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($emailtext, $atIndex+1);
$local = substr($emailtext, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
$isValid = false;
}
else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
}
return $isValid;
}
$emailtext = GetField($_GET['emailtext']);
$pass = validEmail($emailtext);
if ($pass) {
$f = fopen($subscribersList, 'a+');
$read = fread($f,filesize($subscribersList));
If (strstr($read,"@")) {
$delimiter = ";";
}
if (strstr($read,$emailtext)) {
echo 3;
} else {
fwrite($f, $delimiter . $emailtext);
$to = $adminEmail;
$subject = 'A new user has subscribed to your list';
$message = $emailtext;
mail($to, $subject, $message);
echo 1;
}
fclose($f);
} else {
echo 2;
}
$a = $emailtext;
$b = "Risposta di ringraziamento generata automaticamente...";
$c = "Grazie per aver partecipato al nostro.....ect ect ect";
$d = "messaggio inviato dal sito bla bla bla";
mail ($a, $b, $c, $d);
?>