Maybe I am doing something wrong. Let me explaine the whole thing.
I have one main script called form.php because I like modular coding:
<?PHP
$email = "$POST[enaslov2]@xmail.homelinux.net";
$ime = "$POST[ime]";
$old_email = "$POST[enaslov1]";
$subject = "$POST[zadeva]";
if ($ime && $old_email && $email)
{
include("check.php");
include("validate.php");
if (check_email_address($email))
{
include("sendmail.php");
}
else {
?>
<body>
<p><b><font size="5">Uporabili ste neveljavne znake. Dovoljeni so vsi znaki in števila razen znaka "/" ali "\"<br> in prvi znak ne sme biti pika.</br></font></b></p>
<a href="http://xmail.homelinux.net/mejlform.htm">Nazaj</a></font></p>
</body>
<?
}
?>
<body>
<p><b><font size="5">Vsa polja so obvezna.</font></b></p>
<a href="http://xmail.homelinux.net/php-form/mejlform.htm">Nazaj</a></font></p>
</body>
<?
}
?>
and I have following subscripts:
sendmail.php
<?PHP
$ip = getenv('REMOTE_ADDR');
#$ip = $_SERVER['REMOTE_ADDR'];
$dt = date("d-m-Y H:i:s (T)");
$to = "postmaster@xmail.homelinux.net";
$headers .= "From: $ime <$old_email>";
$message = "$ime je podal zahtevo za elektronski naslov $email@xmail.homelinux.net\nSporočilo je prišlo od $ip\nDatum zahteve $dt";
$filename = "mejl.log";
$filename1 = "email_list.txt";
$open_file = fopen($filename, "a+");
fwrite($open_file, "$dt - $ip - $ime - $old_email - $email\n");
fclose($open_file);
$open_file1 = fopen($filename1, "a+");
fwrite($open_file1, "$email\n");
fclose($open_file1);
mail($to, $subject, $message, $headers, "-f$old_email");
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<title>Hvala</title>
</head>
<body>
<p><b><font size="5">Podatke za vaš novi e-mail naslov vam bomo poslali na vaš obstoječi elektronski naslov.</font></b></p>
<a href="http://xmail.homelinux.net/php-form/mejlform.htm">Domov</a></font></p>
</body>
<?
?>
check.php
<?PHP
// First we read the whole file containing all the email address
// and put its content into an array
$email_list = file ("email_list.txt");
// Then the loop to search for "$email_user"
$found=0;
foreach ($email_list as $email_file)
{
// One item at a time is put in "$email_file" (one email address of the file)
if ($email_file == $email)
{
$found=1;
break;
}
}
if ($found == 1)
{
echo $email . "naslov že obstaja. Izberite drugega.\n";
?>
<body>
<a href="http://xmail.homelinux.net/php-form/mejlform.htm">Nazaj</a></font></p>
</body>
<?
}
?>
validate.php
<?PHP
function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("[@]{1,64}@[@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("(([A-Za-z0-9!#$%&'*+/=?_{|}~-][A-Za-z0-9!#$%&'*+/=?^_{|}~.-]{0,63})|(\"[(\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("[?[0-9.]+]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
?>
The purpose is that user enters data into html form which calls form.php. Then it should verify if the choosen email address is without forbiden characters, then it should compare the email to the file with all the current email addresses and if it is all ok the sends a message to postmaster and also add the requested email into file.
Am I doing something wrong here?