Submit Script-News Letter

  • DymeMedia1
  • Novice
  • Novice
  • User avatar
  • Posts: 30
  • Loc: London

Post 3+ Months Ago

Hey guys i believe this to be a simple one but i was having a lil bit of trouble with it ,i want to place a simple submit button and enter text box on the left of it so visitors can enter their email and when click submit have it simply submit their email address to a file on the server so i can simply download the file and open in notepad for example and have the list of email addresses,something simple like that i need a script or code for if possible or a basic newsletter script.

And also if any of you got a nice domain checker script id greatly appreciate it.

Thanks again for all the help :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Here's a script that will append text entered into a box to a simple text file that you can then download. I just threw it together and tested it on my local server and it seems to do what you want. It will open the file in append mode so you needn't create a blank file to start with - if it doesn't already exist it will be created. I also added a simple form, so you can test it out. I would suggest copying and pasting the whole thing into a file with the .php extension, adding whatever name you want and testing it to see if it fits your needs.

If you decide you want to use it, you can separate out the php script as it doesn't need to be on the same page as the form of course, but if you want to use the header function to redirect after submission make sure the script comes before anything else, because you can't send a header after any other output has already been sent.
Code: [ Select ]
<?php
if(isset($email))
{
 $fp = fopen("emails.txt", "a");
 
 if (!$fp) {
 print("Could not append to file");
 exit;
 }
 fwrite($fp,"$email\n");
 fclose($fp);
 
 // address of page to go to after writing to file
 header("Location: http://www.somedomain.com/somepage.html");
}
?>

<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="<? echo $PHP_SELF ?>" method="post">
Email: <input name="email" type="text" /><input type="submit" />
</form>
</body>
</html>
  1. <?php
  2. if(isset($email))
  3. {
  4.  $fp = fopen("emails.txt", "a");
  5.  
  6.  if (!$fp) {
  7.  print("Could not append to file");
  8.  exit;
  9.  }
  10.  fwrite($fp,"$email\n");
  11.  fclose($fp);
  12.  
  13.  // address of page to go to after writing to file
  14.  header("Location: http://www.somedomain.com/somepage.html");
  15. }
  16. ?>
  17. <html>
  18. <head>
  19. <title>Untitled</title>
  20. </head>
  21. <body>
  22. <form action="<? echo $PHP_SELF ?>" method="post">
  23. Email: <input name="email" type="text" /><input type="submit" />
  24. </form>
  25. </body>
  26. </html>
  • SniperDevil
  • Beginner
  • Beginner
  • User avatar
  • Posts: 42

Post 3+ Months Ago

Odd, seems as though fopen is not working... Following is an output of the error I get:

Code: [ Select ]
Warning: fopen(emails.txt): failed to open stream: Permission denied in /home/worksofm/public_html/php/appendform_test.php on line 5
Could not append to file
  1. Warning: fopen(emails.txt): failed to open stream: Permission denied in /home/worksofm/public_html/php/appendform_test.php on line 5
  2. Could not append to file


"Could not append to file" is obviously not a part of the error, it's part of the script, but is PHP not configured right on my server?

<a target="_blank" href="http://www.worksofmagic.com/php/appendform_test.php">www.worksofmagic.com/php/appendform_test.php</a>
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

No, it's working fine. Because I tested it on my local server I forgot completely that you will have to set the file permissions so that you can write to the text file. I created a blank text file names "emails.txt" uploaded it to a remote server and then set chmod to 666 and it worked fine.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I think you'll need to change the newline from \n to \r\n for a linux machine too - at least that's what I needed to do when I uploaded and tried it out on a remote server.
  • DymeMedia1
  • Novice
  • Novice
  • User avatar
  • Posts: 30
  • Loc: London

Post 3+ Months Ago

THank you sooooooo Much for that ! i will test it out now and let you know how it goes but i really appreciate that if im having any trouble ill ask :) thank you once again
  • DymeMedia1
  • Novice
  • Novice
  • User avatar
  • Posts: 30
  • Loc: London

Post 3+ Months Ago

Works Just great ! thanks alot Rich :D
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Now that I'm awake again and had a cup of coffee, I've been playing around with it and got it to work with a chmod of 602 which would probably be a better idea than 666. 602 gives owner read/write permissions and public write permissions, so your users could enter their email addresses through the php script, but couldn't view or download the text file and get the whole address list for themselves (666 gives everybody read/write access).

You could then use your FTP program to view/download the file when you needed it, but anyone typing the url of the file into the browser would get a "403 Forbidden" error.

I'm not an expert at the whole chmod thing, so you might want to experiment a bit yourself, but that was the lowest set of permissions that seemed acceptable on the ipower server where I tested it.
  • DymeMedia1
  • Novice
  • Novice
  • User avatar
  • Posts: 30
  • Loc: London

Post 3+ Months Ago

602 works just fine allows read/write to owner and just write for visitors so a 403 error would come up , so thats perfect :)
  • DymeMedia1
  • Novice
  • Novice
  • User avatar
  • Posts: 30
  • Loc: London

Post 3+ Months Ago

i also wanna use the script for a quick contact form also where they fill in the form fields ( subject name etc ) and it send it to a certain text file ill be playing around with that for a while if i need any help ill be sure to ask again but so far the script is perfect

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: Bogey and 95 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.