Mailing List
|
Voltar // GET EMAIL $email=$_POST["email"]; // To avoid problems, only lower case is used $email=strtolower($email); // Check whether email is correct by using a function // function requires the email address and the error message check_email ($email, "Erro : E-mail não é válido"); ?> // GET VALUE FOR action : subc (subscribe) or unsubc (unsubscribe) $action=$_POST["action"]; // this is the file with the info (emails) // When using the link in the top to download the complete script, a new name for this file // will be generated (p.e.: emaillist-2ax1fd34rfs.txt), so users will be unable to find it $file = "emaillist-50yBvy9RYA.txt"; // lets try to get the content of the file if (file_exists($file)){ // If the file is already in the server, its content is pasted to variable $file_content $file_content=file_get_contents($file); }else{ // If the file does not exists, lets try to create it // In case file can not be created (probably due to problems with directory permissions), // the users is informed (the first user will be the webmaster, who must solve the problem). $cf = fopen($file, "w") or die("Error: file does not exits, and it can not be create. Please check permissions in the directory or create a file with coresponding name."); fputs($cf, "Assinantes\n"); fclose($cf); } ?> // IF REQUEST HAS BEEN TO SUBSCRIBE FROM MAILING LIST, ADD EMAIL TO THE FILE if ($action=="subc"){ // check whether the email is already registered if(strpos($file_content,"<$email>")>0){print("Erro: O seu e-mail já se encontra na nossa base de dados");} // write the email to the list (append it to the file) else{ $cf = fopen($file, "a"); fputs($cf, "\n<$email>"); // new email is written to the file in a new line fclose($cf); // notify subscription print "O seu e-mail foi adicionado. Obrigado."; } } ?> // IF REQUEST HAS BEEN TO UNSUBSCRIBE FROM MAILING LIST, REMOVE EMAIL FROM THE FILE if ($action=="unsubc"){ // if email is not in the list, display error if(strpos($file_content,"<$email>")==0){print("Erro: Não temos qualquer registo do seu e-mail na nossa Base de Dados");} // remove email from the content of the file else { $file_content=preg_replace ("/\n<$email>/","",$file_content); // print the new content to the file $cf = fopen($file, "w"); fputs($cf, $file_content); fclose($cf); // notify unsubscription print "O seu e-mail foi removido da nossa Base de Dados "; } } ?> |
|---|
Links Relaccionados:
Governo Regional
___________________________________________
Direcção Regional da Educação e Ciência
___________________________________________
Ministério da Educação
___________________________________________
IEFP - Instituto de Emprego e Formação Profissional
___________________________________________
Centro de Formação da Associação de Escolas de
São Miguel e Santa Maria
___________________________________________