Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Aza
    Aza is offline
    New Coder
    Join Date
    Jun 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Kind of a mailing list

    Hi all...

    I am chasing some code, similar to a mailing list where someone can enter their email address into a form field, an email is sent to me telling me, and an email is send to the entered address saying thanks etc. and the email address they entered is also stored in a list in a txt file (or similar) which is stored in the same dir as the page containing the script.

    Please no SQL.

    Is this possible?? Any help will be greatly appreciated.

    Cheers!!!

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It may or may not help but have a look at:
    http://www.quirm.net/show.php?contentid=7

    The 1.5 release does have a bug, but so far as I know version 1 is error free (well as free as it can be).

    It'll at least be a good starting point.
    my mind is on a permanent tangent

  • #3
    New Coder
    Join Date
    Jul 2005
    Location
    Perth, Australia. Age: 13
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess you could do it.
    Sign up script
    PHP Code:
    <?php
    if($action=="signup") {
    $name striptags($_POST["name"]);
    $email striptags($_POST["email"]);
    if(empty(
    $email) || empty($name)) // If fields empty
        
    {
            die (
    "Please fill in all the fields");
        }
        
    if(!
    eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\{.[a-z]2,3})?)$'$email))
        {
       die (
    "Please fill in a valid email address");
        
        }

    $file "emails.txt"// Textfile holding emails
    $f fopen("$file""w+") or die ("Couldn't open $file");
    fwrite($f"$email\n");
    fclose($f);

        
    $from "you@email.com"// From
        
    $subject "Thanks for signing up to the mailing list!"// Email subject

        
    $headers "From: WebMaster <$from>\n";

        
    $message "Hi $name, <br><br> Thank you for signing up to our mailing list"// Message
        
        
    if (mail($email,$subject,$message,$headers))    // if email sending is successful
        

     echo 
    "Thanks for signing up";
        }

    else
     {
    ?>
    <form action="<?php echo $SERVER["PHP_SELF"]; ?>?action=signup" method="post">
    <table width="80%" border="0" cellspacing="1" cellpadding="1">
    <tr>
    <td colspan="2">Sign Up Form</td>
    </tr>
    <tr>
    <td>Name:</td>
    <td><input name="name" type="text" maxlength="30"></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input name="email" type="text" maxlength="30"></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    <?php
    }
    ?>
    I dunno if it'll work properly but it should.
    sending an email to all the addresses isn't too hard either.

    Something like this
    PHP Code:
    <?php
    if($action=="send") {
    $emails file("emails.txt"); // Turn each line in file into an array
    foreach($emails as $key => $email// Loop it
      
    {
        
    $from "you@email.com";
        
    $subject $_POST["subject"];
        
    $message $_POST["message"];
        
    $headers "From: WebMaster <$from>\n";

        if (
    mail($email,$subject,$message,$headers))    // if email sending is successful
        

     echo 
    "Newsletter sent";
        }

          else
        {
             echo 
    "Error sending emails";
        }
      }
    }

    else
      {
    ?>
    <form action="<?php echo $SERVER["PHP_SELF"]; ?>?action=send" method="post">
    <table width="80%" border="0" cellspacing="1" cellpadding="1">
    <tr>
    <td colspan="2">Send Newsletter</td>
    </tr>
    <tr>
    <td>Subject:</td>
    <td><input name="name" type="text" maxlength="30"></td>
    </tr>
    <tr>
    <td>Message:</td>
    </tr>
    <tr>
    <td><textarea rows="20" cols="45" name="message"></textarea></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    <?php
      
    }
    ?>
    Last edited by e-Raser; 09-16-2005 at 01:52 PM.
    I lost my signature, have you seen it?
    I have the power to erase you...

  • #4
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That should not be an <input type="textarea"... />. It should be <textarea rows="20" cols="45" name="message"></textarea>.

    But other than that, I didn't look too hardly, the code is right.

  • #5
    New Coder
    Join Date
    Jul 2005
    Location
    Perth, Australia. Age: 13
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Lol, sorry. I didn't really check it.
    Thanks for telling me.
    I lost my signature, have you seen it?
    I have the power to erase you...

  • #6
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    He he... no problem.

    Oh and the row="" and column="" numbers are just random. I don't know if that's how big/small you want it. Change around the values to make it work. The bigger the numbers the bigger the box and vise versa.

    Hope that helps!

  • #7
    New Coder
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just some small corrections:
    change this line:
    PHP Code:
    $f fopen("$file""w+") or die ("Couldn't open $file"); 
    to
    PHP Code:
    $f fopen("$file""a+") or die ("Couldn't open $file"); 
    otherwise you overwrite the existing emails. With a+ you add them to the end of the file.

    The function striptags must be written like this:
    PHP Code:
    $name strip_tags($_POST['name']); 
    instead of striptags.

    And if there'll be a lot of mails in the list, there will be the problem of timing out before all mails are sent. Anybody has a suggestion for that?

    Matthijs

  • #8
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ahhh ok I've just been working on an integrated newsletter script for another project, and decided to start afresh. I came up with:
    Use the following inside the loop where emails are being sent:
    PHP Code:
    ignore_user_abort(TRUE);
    set_time_limit (0);
    ob_end_flush();
    ob_start();
    ob_flush();
    flush(); 
    Though whether that is the right way or not is another thing entirely :-)
    my mind is on a permanent tangent

  • #9
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you are wanting to send alot of e-mails (i mean alot) then you are much better of using an SMTP script rather than just stopping time limits... SMTP is much faster for this kind of thing, and you can get some great free scripts such as http://phpmailer.sourceforge.net/

  • #10
    New Coder
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Funny, I was just a) looking for a mailinglistmanager, b) playing with the phpmailerclass (tutorial http://www.phpfreaks.com/tutorials/130/0.php) and c) checking out simple PHP newsletter http://www.quirm.net/showcategory.php?categoryid=14 and then I saw your reply Rich. You did make the release 1.5 of simple PHP newsletter didn't you? So how is development going? Any news? Is it a stable version or does it need bugtesting? I'm really interested, as I have the same problems you encountered when you were looking for a good news/mail manager. Either it's too bulky with soo many features, it's full of bugs, not safe, no development, etc. I'd prefer to have a really simple script, just doing what I want but very stable and safe, then using a huge package with bugs and leaks.... I also could try to help if you want.

  • #11
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Situation is thus regarding simple php newsletter

    It isn't that simple, and I adapted it from someone elses. Looking back now that I have learnt more I can see tons of mistakes, though the guy that updated it to 1.5 has fixed a fair few.

    There is so much in it that is redundant it is unbelievable, so even for a project I had I started afresh. So for the time being work on those scripts have halted.
    (not only that but 'so called work' committments have meant I have had to shelve a lot of the free projects i was working on).


    Looks like I have to investigate smtp rather than php mail...
    my mind is on a permanent tangent

  • #12
    Aza
    Aza is offline
    New Coder
    Join Date
    Jun 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Hi guys...

    I have copied and pasted e-Raser's code and made matthijs's changes to the first page (signup.php). Uploaded it and when I call that page I get this

    Parse error: parse error in /var/www/html/dev/signup.php on line 56

    The mailout page (mailout.php) works great.

    Any ideas what could be causing this?

    Thanks everyone for you help so far...so close!

    Cheers

  • #13
    New Coder
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    you're right, there was another small change. It's got to do with the brackets. I'll just show you what I've got now, so you can compare your code with mine:
    PHP Code:
    <?php
    /* simple mailinglist scrip made by "Eraser"
    *  on :  http://www.codingforums.com/showthread.php?t=68293
    *  09-16-2005, 12:24 PM
    ---------------------------------------------------------------------------- */
    if($action=='signup') {
        
    $name strip_tags($_POST['name']);
        
    $email strip_tags($_POST['email']);
        if(empty(
    $email) || empty($name)) // If fields empty
          
    {
            die (
    "Please fill in all the fields");
           }
        if(!
    eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\{.[a-z]2,3})?)$'$email))
          {
             die (
    "Please fill in a valid email address");
          }
      
          
    $file "emails.txt"// Textfile holding emails
        
    $f fopen("$file""a+") or die ("Couldn't open $file");
        
    fwrite($f"$email\n");
        
    fclose($f);

        
    $from "you@email.com"// From
        
    $subject "Thanks for signing up to the mailing list!"// Email subject

        
    $headers "From: WebMaster <$from>\n";

        
    $message "Hi $name, <br><br> Thank you for signing up to our mailing list"// Message
        
        
    if (mail($email,$subject,$message,$headers))    // if email sending is successful
        

           echo 
    "Thanks for signing up";
        }
    }
    ?>
    <form action="<?php echo $SERVER["PHP_SELF"]; ?>?action=signup" method="post">
    <table width="80%" border="0" cellspacing="1" cellpadding="1">
    <tr>
    <td colspan="2">Sign Up Form</td>
    </tr>
    <tr>
    <td>Name:</td>
    <td><input name="name" type="text" maxlength="30"></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input name="email" type="text" maxlength="30"></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    As you see, I only have one if($action=='signup') { do this } statement, and then the form. No else.

  • #14
    New Coder
    Join Date
    Jul 2005
    Location
    Perth, Australia. Age: 13
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry about that, I only put in the else because without it it'd echo the message above the form. Though that wouldn't be much of a problem ^^0
    I really didn't look over it to carefully so excuse my mistakes.
    I lost my signature, have you seen it?
    I have the power to erase you...

  • #15
    Aza
    Aza is offline
    New Coder
    Join Date
    Jun 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks

    Thanks to everyone who posted and a big thanks to matthijs & e-Raser.

    Cheers all!!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •