Posted By

pgmr on 03/19/09


Tagged

email mysql database sql php list csv no mailing flatfile


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

pgmr
diesel


Mailing List - No database, just flatfile - CSV formatting


 / Published in: PHP
 

URL: http://www.pgmr.co.uk

Make sure you create the email.txt! The file can be accessed so password protect it or something. Email.txt will save it in CSV format.

  1. <?php
  2.  
  3. /**
  4.  * Mailing List Script
  5.  * Copyright 2009 - www.pgmr.co.uk - [email protected]
  6.  */
  7.  
  8. function showForm() {
  9. echo '
  10. <form method="post" action="">
  11. Email Address: <input type="text" name="email"> <br />
  12. <input type="submit" value="Submit" name="submit">
  13. </form>
  14. ';
  15. }
  16.  
  17. if(empty($_POST['submit']) === false) {
  18. $email = htmlentities(strip_tags($_POST['email']));
  19.  
  20. $logname = 'email.txt';
  21. $logcontents = file_get_contents($logname);
  22.  
  23. if(strpos($logcontents,$email)) {
  24. die('You are already subscribed.');
  25. } else {
  26. $filecontents = $email.',';
  27. $fileopen = fopen($logname,'a+');
  28. $filewrite = fwrite($fileopen,$filecontents);
  29. $fileclose = fclose($fileopen);
  30. if(!$fileopen or !$filewrite or !$fileclose) {
  31. die('Error occured');
  32. } else {
  33. echo 'Your email has been added.';
  34. }
  35. }
  36. } else {
  37. showForm();
  38. }
  39.  
  40. ?>

Report this snippet  

You need to login to post a comment.