Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

[php] Simple Newsletter Script


22 replies to this topic

#1 cragllo

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 933 posts

Posted 04 August 2005 - 02:20 PM

This tutorial will give you the code needed and tell you how to implement it.

First off you need to create a file called mailing.php this will be the file that processes the adding of emails to the list.
<?php
$email = $_POST['email'];
$file = fopen("mailing.txt", "a");
fwrite($file, "\n" . $email);
fclose($file);

header("Location: mailing_thankyou.php");
?>

Next you need to create a file called mailing_thankyou.php, simple a page thanking them for signing up.

Now create a file called mailing.txt with nothing in it, when uploaded to the server set it writable (chmodd 666 or 777).

Now you need to form for teh people to enter their email address, put this on any page
<form action="mailing.php" method="post" class="style16">
<input type="text" name="email" size="30" value="your email here!">
<input type="submit" value="GO!" name="submit">
</form>

Now you need a file to send the newsletter, create a file called anything you want.
<?php
$send = $_POST['send'];
if($send){
		$email = $_POST['email'];
		
		$emailfile = file_get_contents("mailing.txt");
		$emaillist = explode("\n", $emailfile);
		
		foreach ($emaillist as $value)
		{
		mail($value, $_POST['subject'], $_POST['message'], "From: $email");
		}
		
		echo "<b>Email sent!</b><br />";
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
  <table width="481" border="0" cellspacing="0" cellpadding="0">
				<tr valign="top">
				  <td width="84" align="right" valign="top" class="style32">Subject:</td>
				  <td width="397" align="left" class="style32">
					  <input name="subject" type="text" id="subject" size="41" maxlength="100">
				  </td>
				</tr>
				<tr valign="top">
				  <td width="84" align="right" valign="top" class="style32">From:</td>
				  <td align="left" class="style32"><input name="email" type="text" id="email" size="41" maxlength="100"></td>
				</tr>
				<tr valign="top">
				  <td align="right" valign="top" class="style32">Message:</td>
				  <td align="left" class="style32">
					  <textarea name="message" cols="37" rows="4" id="message"></textarea>
				  </td>
				</tr>
				<tr valign="top">
				  <td align="right" valign="top" class="style32">&nbsp;</td>
				  <td align="left" class="style32">
					  <input name="send" type="submit" id="send" value="SUBMIT">
					  <input name="Reset" type="reset" id="Reset" value="RESET">
				  </td>
				</tr>
  </table>
</form>

Thats you all done, to send the newsletter, simply go to the file you just created fill in the spaces, and click send, there is no warning/confirmation. so check before you send!

Please note: I will be improving on this script as time goes on, hopefuly to make it able to remove people from the list too, So check back soon!

Edited by cragllo, 14 January 2007 - 08:18 PM.


#2 BlaqueMajik

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 64 posts
  • Location:Scottsdale, AZ

Posted 05 August 2005 - 04:05 AM

Great tut. Well explained and one of few I have seen on this topic.

I will use it on my site when I get it up and running. Thank you.

#3 kraam

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 56 posts

Posted 08 August 2005 - 02:11 AM

Thats a good tutorial it will become very handy one day.

#4 pilgrim_of_mini-monkeys

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 138 posts
  • Location:United Kingdom
  • Interests:I am boring. I have no interests. Leave me alone.

Posted 08 August 2005 - 05:51 AM

Thank you so much. I am a dunce when it comes to PHP (I can understand it, but writing it is a different matter).

You would not believe the extenct of which I have searched the Internet trying to find such a script.

However, is it a flat file php script? There seems to be no mention of database, after all, wouldn't it need a database connection to retrieve the list of people who are signed up?

#5 major9

    Newbie [Level 2]

  • Kontributors
  • PipPip
  • 26 posts

Posted 08 August 2005 - 08:38 AM

thanx man i am going to put this script in my site.

#6 Adamrosso

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 128 posts

Posted 08 August 2005 - 09:01 AM

Nice script, i will defantly use this on my website =D

#7 cragllo

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 933 posts

Posted 08 August 2005 - 10:57 AM

pilgrim_of_mini-monkeys said:

Thank you so much. I am a dunce when it comes to PHP (I can understand it, but writing it is a different matter).

You would not believe the extenct of which I have searched the Internet trying to find such a script.

However, is it a flat file php script? There seems to be no mention of database, after all, wouldn't it need a database connection to retrieve the list of people who are signed up?

First of, I am exactly the same as you, I know how PHP works, what it can do, and I can easily edit php scripts, but writing my own is hord, I'm still learning but I know the basics and more.

Secondly, This scripts is flat file, all emails are saved in mailing.php (each on a new line), I am currently working on the part to search through that file and remove emails from the list.

#8 pilgrim_of_mini-monkeys

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 138 posts
  • Location:United Kingdom
  • Interests:I am boring. I have no interests. Leave me alone.

Posted 08 August 2005 - 03:01 PM

Cool. Thanks. I really need to start learning PHP.

#9 soniku

    Newbie

  • Kontributors
  • Pip
  • 2 posts

Posted 09 August 2005 - 12:04 PM

cool script -_-

#10 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 02 March 2009 - 03:40 AM

Great Script!! - newsletter sign up form php[php] Simple Newsletter Script

Excellent. Just installed this and worls perfectly. I literally spent hours looking for a simple script like this and no one had one. Every script was too complex or too hard to follow.  Nice job and thank you!

Also, all emails arrive in the text file. Can you show us how to import these into a database? Thanks again!

-reply by S-base

 






Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users