Jump to content
xisto Community
cragllo

[php] Simple Newsletter Script

Recommended Posts

remove email from list

 

 Simple Newsletter Script

 

 

 

<p>hi, remove email script, please ignore previous one...</p>

<p> </p>

<p><?php

 

 

if( isset($_GET['remove']) and $_GET['remove'] == "yes"){

 

 

 

   $remove_email = $_GET['email_remove'];

 

   

 

   $taken_email = array();

 

   

 

$emailfile = file_get_contents("mailing.Txt");

 

  $emaillist = explode("and", $emailfile);

 

 

 

  foreach ($emaillist as $value)

 

  {

 

     if ( $remove_email != $value ){

 

       $taken_email[] = $value;

 

     }

 

  }

 

   

 

   $value = "";

 

   $file = fopen("mailing.Txt", "w+");

 

   foreach ($taken_email as $value)

 

  {

 

     if( trim($value) != "" ){

 

       $email = $value;

 

       fwrite($file, "and" . $email);

 

     }

 

   }

 

   

 

   fclose($file);

 

 

   

 

}

 

 

?></p>

 

-reply by majid


Hi,

 

After I upload the remove email script then what do I do to remove the emails from the mailing.txt? I tried

http://example.com/unsubscribe.php?email=example@gmail.com

Edited by afunguy26 (see edit history)

Share this post


Link to post
Share on other sites

It would have to be site.com/remove.php?remove=yes&email_remove=email@domain.com

Judging by the two GET variables.

So you can send out a link with the newsletter with a premade HREF tag that plugs in the individual user's email address into the email_remove variable.

Need more details please....

 Simple Newsletter Script

Hi, I am setting up my first website through Website Tonight and am trying to figure out how to do an e-mail sign-up box for a newsletter. I see your instructions but I guess I don't know what php is, or where to create the files you say to create - is this all done on the website, or in Word, or in some other kind of program? I'm sorry for my stupidity - I am still learning!
-question by Caryn
I would strongly suggest looking for another script to send out newsletters, this isnt super beginner friendly (though its perfectly well made!). If you want to host a reliable site you will need to learn a bit about how the web works and at least touch upon HTML, just to fix little bugs in code etc....

To create a website you need to create code, HTML to be precise, this is done usually in a specific editor, things like Word really arent any good, even though they will tell you they can create websites they really cant and you will run into endless problems. PHP is just another type of code that works in the background. Like the engine of a car, you as a driver never see it, you just give it input (gas, change gears, ignition) and it does some work that you know nothing about, all you know is that the car starts and changes speed. Thats PHP. The bodywork of the car is like HTML, you see it, it holds everything together where the engine (or PHP) does all the heavy work in the background.

Share this post


Link to post
Share on other sites

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"> </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!

I wanted this script for my website so now I will not have search the sollution it seems simple. Thanks for tutorial...

Share this post


Link to post
Share on other sites

Hi,
After I upload the remove email script then what do I do to remove the emails from the mailing.txt? I tried

http://example.com/unsubscribe.php?email=example@gmail.com

I am also wondering how to remove email with this code. Thanks for the script. I added a wysiwyg editor to this script to send HTML emails. Worked like a charm!

Thanks!

Share this post


Link to post
Share on other sites

I am also wondering how to remove email with this code. Thanks for the script. I added a wysiwyg editor to this script to send HTML emails. Worked like a charm!
Thanks!



Hello can share the script with the wysiwyg editor you added please?

Share this post


Link to post
Share on other sites

hello,i was wondering how i can edit textarea? or instead of textarea can i put reguar html code?like "div style="width:500px;backgorund-color:#eee"><a href="#" > click here</a> </div>"instead of textarea i want to style message with link and button..how can i do it?thank you

Share this post


Link to post
Share on other sites

Hello there!

 

Thank you very much for the script, it works perfectly. I only have one issue and maybe it is my fault but if you try to access the txt file by writing the full address (i.e http://www.yourdomain.com/mailing.txt) anyone can see the full list of subscribers... Is there any way to make that hidden or something?

Share this post


Link to post
Share on other sites

Hello there!
Thank you very much for the script, it works perfectly. I only have one issue and maybe it is my fault but if you try to access the txt file by writing the full address (i.e http://www.yourdomain.com/mailing.txt) anyone can see the full list of subscribers... Is there any way to make that hidden or something?

Add this to your .htaccess:
<FilesMatch ".\.txt$">Deny from all</FilesMatch>

Share this post


Link to post
Share on other sites

Keep in mind that this is just for a single-opt-in it looks like. Most web hosts will require you to use double-opt-in or else you can have your account deactivated due to spam. So before using this on a live server, look into a safer way to build the database of email addresses.

Share this post


Link to post
Share on other sites

Thank you. rpgsearcherz

 

i will keep that in mind and if i decide to you it i will test it first.

thank you again.

 


No problem. I think it would be somewhat easy to adapt for the double-opt-in. All you'd need to do is have it store two new variables for "tempid" or something and "active," in the database. Tempid would be randomly generated and would be what's sent out in a verification email (upon which clicking it would verify the email/id do match), and the active block would tell whether or not it's been verified already.

Share this post


Link to post
Share on other sites

Hello there!

 

Thank you very much for the script, it works perfectly. I only have one issue and maybe it is my fault but if you try to access the txt file by writing the full address (i.e http://www.yourdomain.com/mailing.txt) anyone can see the full list of subscribers... Is there any way to make that hidden or something?

 

Alternately, move the file outside of the web accessible portion of your account and then reference the file in the script using a "relative" link.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.