PHP script sender kun mail nogengange
jeg har lavet et lille PHP script så brugeren kan skrive sig op til et nyhedsbrev.Problemet er det kun sende en mail nogen gange
Håber nogen kan hjælpe mig med hvorfor det kun virker nogle gange ??
her er min test side
http://www.jart.dk/jgom/php-test/mail-test.php
selve scriptet ser sålede ud (min mail ændret her)
-------
<?php
// **************************************************************************
// NAME THE MAIL INFORMATION FILE (AND ITS URL) AND CHANGE THE MESSAGES AS YOUR WANT
// **************************************************************************
$file = "maillisten.txt"; // the mail information file (url)
// FORM MESSAGES
$mainmessage = "Insert your Email"; // start messages
$errormessage1 = "Error: The Email is not valid"; // error messages
$errormessage2 = "Error: The server dont exist";
$errormessage3 = "Your Email is already on the mailing list";
$errormessage4 = "Your Email is not on the mailing list";
$message1 = "Your Email has been added.<br>Thanks for joining."; // subscription messages
$message2 = "Your Email has been removed. ";
// MAIL INFOMATION
$from_email="JGOM <min@mail.dk>"; // yourdomain.com must be your real domain
$replayto="min@mail.dk"; // replay to email adress
// MAIL MESSAGES
$mail_subject1="Confermation of your subscribtion to JGOM News Mail"; // subscribe confermation email
$mail_message1="Your email has been added to the JGOM News Mail list.
Thanks for joining.
Best regards
Jesper G.O. Møller
---------------------------------------------------------------------
If its not you that have subscribe to the JGOM News Mail list
Pleas go to http://www.jart.dk/jgom/ to remove you from the list...
";
$mail_subject2="Confermation of your removal from JGOM News Mail"; // unsubscribe confermation email
$mail_message2="Your email has been removed from the JGOM News Mail list.
Best regards
Jesper G.O. Møller
-----------------------------------------------------------------
If its not you that have unsubscribe from the JGOM News Mail list
Pleas go to http://www.jart.dk/jgom/ to add you to the list...
";
// **************************************************************************
$message = $mainmessage;
$email = "";
$formcheck = 0;
if (!$_POST){make_form($message);
}else{
$email=$_POST["email"];
$email=strtolower($email);
$action=$_POST["action"];
if ($email==""){
$message = $mainmessage;
$formcheck = 1;
}else{
$emailcheck=trim($_POST["email"]);
$pattern = "^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$";
if (!eregi($pattern, $emailcheck)){
$message = $errormessage1;
$formcheck = 1;
}else{
$email_server=substr($email,strpos($email, "@")+1);
if (checkdnsrr($email_server)!=1){
$message = $errormessage2;
$formcheck = 1;
}
}
}
if ($formcheck==0){
if (file_exists($file)){
$file_content=file_get_contents($file);
}else{
$cf = fopen($file, "w") or die("Error: file can not be create.<BR>Please check permissions.");
fputs($cf, "News Mail subscribers\n");
fclose($cf);
}
}
if ($formcheck==0){
if ($action=="subc"){
if(strpos($file_content,"<$email>")>0){
$message = $errormessage3;
$formcheck = 1;
}else{
$cf = fopen($file, "a");
fputs($cf, "\n<$email>");
fclose($cf);
mail($email, $mail_subject1, $mail_message1,"From: $from_email\nReply-To: $replayto\nContent-Type: text/plain");
$message = $message1;
$formcheck = 1;
flush();
}
}
}
if ($formcheck==0){
if ($action=="unsubc"){
if(strpos($file_content,"<$email>")==0){
$message = $errormessage4;
$formcheck = 1;
}else{
$file_content=preg_replace ("/\n<$email>/","",$file_content);
$cf = fopen($file, "w");
fputs($cf, $file_content);
fclose($cf);
mail($email, $mail_subject2, $mail_message2,"From: $from_email\nReply-To: $replayto\nContent-Type: text/plain");
$message = $message2;
$formcheck = 1;
flush();
}
}
}
make_form($message);
}
function make_form($message){
?>
-----------
