Har lige leget med et lille script til at til/framelde sig et nyhedsbrev.
Du er velkommen til at bruge det hvis du kan/vil
Scriptet er kun lavet til mailadressen
Scriptet laver en txt fil med alle adresserne (Den bør være read/write Owner only)
Tilpas informationerne mellem ******* linierne og sæt det hele ind på siden
Omdøb siden til .php
--------------------------------
<?php
// **************************************
$file = "componenter/listen.txt";
$mainmessage = "Insert your Email";
$errormessage1 = "Error: The Email is not valid";
$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.";
$message2 = "Your Email has been removed. ";
$from_email="John D <john@mydomain.com>";
$replayto="john@mydomain.com";
$mail_subject1="Confermation of your subscribtion to News Letter";
$mail_message1="Your email has been added to the News Letter list.
Thanks for joining.
Best regards
John D
---------------------------------------------------------------------
If its not you that have subscribe to the News Letter list
Pleas go to
http://www.mydomain.com/ to remove you from the list...
";
$mail_subject2="Confermation of your removal from News Letter";
$mail_message2="Your email has been removed from the News Letter list.
Best regards
John D
-----------------------------------------------------------------
If its not you that have unsubscribe from the News Letter list
Pleas go to
http://www.mydomain.com/ 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){
?>
<form action="<? $PHP_SELF; ?>" method="post">
<table>
<tr>
<td></td>
<td colspan="3"><big style="font-weight: bold;">Sign up for News Letter</big></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="3">
<!-- Message -->
<?php
print ($message);
?>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="3"><input name="email" size="30" type="text"></td>
<td></td>
</tr>
<tr>
<td></td>
<td ><input name="action" value="subc" type="radio" checked>Subscribe</td>
<td></td>
<td ><input name="action" value="unsubc" type="radio" c>Unsubscribe</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input value="Submit" type="submit"></td>
<td></td>
<td></td>
</tr>
</table>
</form>
<?php
}
?>