Web Develop Forum: Keep me informed script - Web Develop Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Keep me informed script Let users submit their email to find out when something's launched Rate Topic: -----

#1 User is offline   Christian Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 11-January 09

Posted 28 January 2009 - 09:32 AM

Hey Guys, heres a simple script so that you can let your users enter their email and it goes to a .txt file. Great for coming soon sites, newsletters, etc.

CODE
  <form id="form1" name="form1" method="post" action="">
  <form action="/email.php" method="post">
     <label for="email">Email:</label>
               <input name="email" type="text" id="email" size="40">
               <input type="submit" value="Inform Me!" />
     <label for="lastname"></label>
  </form>    </form>


This is the HTML form you put on your website where you want the box to be displayed.


Create a file named email.php and place this code in it:
CODE
<?php
$filename = "emails-4214.txt"; #you gotta chmod this to 666
$text = $_POST['email'];


$fp = fopen ($filename, "w"); # you don't have to make the .txt file, this line will do it for you id you don't already have it
if ($fp) {
fwrite ($fp, $text);
fclose ($fp);
echo ("Gratzi for teh emailz!"); #change the txt to what you want it to say when they submit the form
}
else {
echo ("Oh Noes! You Broke my ******* site!"); #Change the text to what you want it to say in the rare occurance that there's an error :o
}

?>

Place this code in the file called emails.php and upload it to the server, after that submit the first email and the file will be created. Pretty simple little script.. You can check out a demo of it @ www.yozoe.com

C

This post has been edited by -Gareth: 28 January 2009 - 03:51 PM
Reason for edit: No swearing, please.

0

#2 User is offline   Gaz Icon

  • Advanced Member
  • Icon
  • Group: Administrators
  • Posts: 178
  • Joined: 15-January 09
  • Gender:Male
  • Location:UK

Posted 28 January 2009 - 03:51 PM

Wouldn't a database be better than a txt? Also, please do not swear, even in your code.
0

#3 User is offline   Diffraction Icon

  • Advanced Member
  • Icon
  • Group: Moderator
  • Posts: 279
  • Joined: 26-January 09
  • Gender:Male
  • Location:USA
  • Interests:Web Development, Reading, Writing, Computers in general...
  • Your specialities (detailed)::HTML 5
    CSS 3
    jQuery

Posted 28 January 2009 - 04:06 PM

Since this is so light weight, a text file would be more appropriate.
Want to report something to a moderator? Use the 'report' button located on every post.
0

#4 User is offline   Christian Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 11-January 09

Posted 28 January 2009 - 08:35 PM

Sorry about that, and its really a personal preference, I prefer a txt form just because it's easier to get the emails from, but yes it could be done with a database, just seems like an unnecessary amount of work to me.

Christian
0

#5 User is offline   Salathe Icon

  • Advanced Member
  • Icon
  • Group: Moderator
  • Posts: 138
  • Joined: 15-January 09
  • Gender:Male
  • Location:Scotland

Posted 28 January 2009 - 10:00 PM

This will only ever keep the last email that was submitted via the form. It'll only keep the last whatever (you're not restricted to only sending email addresses) because the "w" flag in fopen truncates the file to zero length (ie, deletes anything already in there). If you want to append the latest email to a list, use the "a" mode.

For what it's worth, I'd also likely use a SQLite database since they are tiny, portable and easy to work with. That way you can store other potentially useful information (IP address maybe, date and time of signing up, etc.), also it would be easier to prevent repeated sign-ups and other blunders.
salathe@php.net
0

#6 User is offline   Gaz Icon

  • Advanced Member
  • Icon
  • Group: Administrators
  • Posts: 178
  • Joined: 15-January 09
  • Gender:Male
  • Location:UK

Posted 30 January 2009 - 09:43 AM

Moved. Please use the correct forum in future!
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users