Scusami ma non mi trovo, come verrebbe il codice? Cosi:
Codice PHP:
<?
include("config.php");
function checkmail ($email)
{
global $listfile;
$fd = fopen ($listfile, "r");
$contents = fread ($fd, filesize ($listfile));
fclose ($fd);
if (@stristr($contents,$email))
$valid = "invalid";
if (eregi("^[_\.0-9a-z-]+@([0-9a-z][-0-9a-z\.]+)\.([a-z]{2,3}$)", $email) && !isset($valid))
$valid = "valid";
else
$valid = "invalid";
return $valid;
}
if ($action == "subscribe" && isset($email))
{
$valid = checkmail($email);
if ($valid == "valid")
{
$fp = fopen($listfile, 'a+');
flock($fp,2);
fwrite($fp,"".strtolower($email).",");
fclose($fp);
mail($email,"Messaggio di benvenuto",file_get_contents("messaggio_benvenuto.txt"));
echo "<script type=\"text/javascript\">
alert('Benvenuto.');
</script>"
exit;
}
else {
header ("Location: ".$error."");
exit;
}
}
elseif ($action == "unsubscribe" && isset($email))
{
$fd = fopen ($listfile, "r");
$contents = fread ($fd, filesize ($listfile));
fclose ($fd);
$allpeople = "";
$entries = explode(",",$contents);
for($i=0;$i<count($entries);$i++)
{
if (strtolower($email) == strtolower($entries[$i]))
$found = "yes";
elseif ($entries[$i] != "")
$allpeople .= "".$entries[$i].",";
}
if ($found == "yes")
{
$fp = fopen($listfile, 'w');
fwrite($fp,$allpeople);
fclose($fp);
}
echo "<script type=\"text/javascript\">
alert('Arrivederci.');
</script>"
exit;
}
else
echo "<script type=\"text/javascript\">
alert('Errore.');
</script>"
exit;
?>