Page 2 of 14 FirstFirst 123412 ... LastLast
Results 11 to 20 of 137

Thread: javascript? php? simple mailing list database?

  1. #11
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi There,

    Ok I have tried this for myself... What do I need to edit in the code for it to send me an email... When someone subscribes? or Leaves? Here is my tester page:
    http://www.curiousclothing.com/email_form_test.php

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You can take out my two comments in the script... if you want, that is.


    Does it seem to work for you?


    Sure... you can do that. I'm no expert with the mail function.

    Here's a possible version... look for "mail" at php.net if you want something else...

    mail("your@email.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
    (it's mail(to, subject, message))
    PHP Code:
    <?php
    if ($email stripslashes($_POST['email'])) {
        
    $filename "emails.phplist";
        
    $filecontents = @file_get_contents($filename);
        if (
    $_POST['choice'] == "join") {
            if (
    strpos($filecontents) != "") break; 
            if (
    strlen($filecontents) > 0$comma ", ";
            
    $add $comma.$email;
            
    $emails $filecontents.$add;
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$emails);
            @
    fclose($file);
            
    $message "Your email was added to the mailing list.".
            
    "<br>Redirecting to the last page.";
        }
        elseif (
    $_POST['choice'] == "leave") {
            
    $edited str_replace($email,"",$filecontents);
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$edited);
            @
    fclose($file);
            
    $message "Your email was removed from the mailing list.".
            
    "<br>Redirecting to the last page.";
            }
        
    ////ADD BELOW
        
    mail("your@email.com""Newsletter Nofication""This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
        
    ////ADD ABOVE
        
    }
    if (
    $message != "") die("<html><head>".
    "<meta http-equiv=\"refresh\" content=\"3;url=\">".
    "</head><body>".$message."</body></html>");
    ?>
    I *think* that will work, but I've had problems with the function before... fairly complex in some ways. you can add more, but in this case, its just a note to you, so probably fine.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried this version but the email never actually comes to me... Also says there is a line error code... Another thing is when they click submit is it possible to take it to the original page but just remove the form field and instead say your email has been added/removed?

    With the previous code... What was it actually doing? was this creating a database of emails?

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    they are the same... the email is now added to the code above, but it's the same code.
    it saves the emails to a text file, emails.phplist (don't be confused by the file extension... they don't mean anything... it's a text file).


    well.... the redirect accomplishes that. If you remove the option to change, then you're not letting them leave the list, or join back up if they left.


    Hmm... I suppose it's not that complex.


    PHP Code:
    <?php
    if ($email stripslashes($_POST['email'])) {
        
    $filename "emails.phplist";
        
    $filecontents = @file_get_contents($filename);
        if (
    $_POST['choice'] == "join") {
            if (
    strpos($filecontents) != "") break; 
            if (
    strlen($filecontents) > 0$comma ", ";
            
    $add $comma.$email;
            
    $emails $filecontents.$add;
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$emails);
            @
    fclose($file);
            
    $message "Your email was added to the mailing list.".
            
    "<br>Redirecting to the last page.";
        }
        elseif (
    $_POST['choice'] == "leave") {
            
    $edited str_replace($email,"",$filecontents);
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$edited);
            @
    fclose($file);
            
    $message "Your email was removed from the mailing list.".
            
    "<br>Redirecting to the last page.";
            }
        
    mail("your@email.com""Newsletter Nofication""This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
        }
    ?>
    //YOUR HTML HERE
    <?php if ($message != "") { echo $message; }
    else { 
    ?>
    <form action="" method="post">
    Join our newsletter!<br>
    Email: <input type="text" name="email"><br>
    <select name="choice">
    <option value="join">Join</option>
    <option value="leave">Leave</option>
    </select>mailing list.<br>
    <input type="Submit" value="Go!">
    </form><?php ?>
    //THE REST OF YOUR HTML HERE
    I think that should work.


    Dunno about the mail thing. some servers vary. Let's see if anyone else knows... I've never really understood the ins and outs of that function.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #15
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It sent me the email but just stayed on the redirect page with this
    Warning: Wrong parameter count for strpos() in /home/virtual/site750/fst/var/www/html/email_form_test.php on line 6
    Your email was added to the mailing list.
    Redirecting to the last page.
    Should I just have 2 pages one saying "your now on the subscribtion list" and the other saying "you have been removed from the subscription list"... And then it loads either one depending?

    Also the email comes from Apache, any way to make it come from the person who emailed it? Or is that impossible?

  6. #16
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I guess similar to this: http://www.php-scripts.com/

  7. #17
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

  8. #18
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    hmmm... if you put an @ symbol before a function, it will suppress warnings...
    if (@strpos($filecontents) != "") break;
    if (@strlen($filecontents) > 0) $comma = ", ";

    However, I think I didn't do that correctly...
    yeah... here... sorry:
    if (strpos($filecontents, $email) != "") break;
    if (strlen($filecontents, $email) > 0) $comma = ", ";




    The example you posted... it just goes to a different page. I assumed that this was going to be placed ON a page, like www.theforce.net -- look on the right, about 3/5 of the way down.

    If this is JUST a page with the form on it, like one you'd get to by clicking a a link to "join the newsletter"... seems like extra work, I'd say put it on the main page.
    However... if you want that, then make the action of the form be the second page, and have the php at the top of that second page. That would work fine.
    that's what the example you posted does.


    Yeah... the php-scripts site... same as mine... its embedded on the page. that makes more sense to me. And, the way I have it setup, it'll just submit, display a message, and redirect back to the main site. (or you can skip the redirect/message page, like we've been talking about).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #19
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I agree with you definitely better going this way... It still has issues though: http://www.curiousclothing.com/email_form_test.php... I'm also a bit confused I think it'd be better once it eventually redirects to the page if the submit and email was all gone and in its place just had thank you for submitting... I'm thinking that some people might try again, you know what I mean?

  10. #20
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You changed both lines?

    True... the newest code I gave you should avoid that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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