www.webdeveloper.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 37

Thread: Running Mail List Tutorial...!

  1. #1
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64

    Running Mail List Tutorial...!

    At this test position

    I would not have requirement for a full blown mass mailer.

    Small number facility would suffice that could provide for a couple of hundred emails on lists. With that in mind and also to learn something of the workings of same scripts I am experimenting with the tutorial that I found at this link.

    Not having success creating a New List which takes place on the newlist.php page with a controlling Form Action="makenewlist.php"

    php Code on the index.php page as follows:

    PHP Code:
    <?php 
    $groups 
    file("data/lists.txt"); 
    for (
    $index=0$index count($groups); $index++)
    {
    $grouplist split("\|"chop($groups[$index]));
    ?>
    <option value="<?php echo $grouplist[1?>"
    <?php if ($index==0)
    {echo 
    "selected";} ?>>
    <?php echo $grouplist[0?><br>
    <?php
    }
    ?>
    and the makenewlist.php as follows:

    PHP Code:
    <html><head><title>Updating file....</title></head><body> 
    <?$Filename $Filename.".lst";$myfile fopen("data/lists.txt","w");fputs($myfile,$Listname."|".$Filename."\n");fclose($myfile);?>Created new list <? echo $Listname ?>.<br>
    <br></body></html>
    I am getting a 500 internal server error - I think it is being caused by the makenewlist.php

    Is there something obvious in the text of the turorial that my php inexperience is not picking up on and thus impacting on the New List creation?

    Is it sensible to convert .php3 extension to .php extension?

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Code seemed alright. You were using short tags in the makenewlist.php file that might not have worked on your server. Also, the $Filename and $Listname would have to have been defined somewhere before the script runs.

    I would have written the files more like this:

    index.php
    PHP Code:
    <?php

        $groups 
    file('data/lists.txt');
        for (
    $index 0$index count($groups); $index++) {
            
    $grouplist explode('|'rtrim($groups[$index]));
            echo 
    '<option value="' $grouplist[1] . '"' . (!$index ' selected="selected"' '') . '>' $grouplist[0] . '</option>';
        }

    ?>
    makenewlist.php
    PHP Code:
    <html><head><title>Updating file....</title></head><body>
    <?php

        $Filename 
    $Filename '.lst';
        
    $myfile fopen('data/lists.txt''w');
        
    fputs($myfile$Listname '|' $Filename "\n");
        
    fclose($myfile);

    ?>Created new list <?php echo $Listname?>.<br />
    <br /></body></html>
    At the moment the list file is being overwritten, but if you want to append new entries instead then change the fopen line to:

    PHP Code:
    $myfile fopen('data/lists.txt''a'); 

  3. #3
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Thanks bionoid.

    I have modified the files with the suggsted script upgrade. When I browse to the Make a List form and fill out the two fields I still get the 500 server error.

    I shall also query with my hosting provider to see if a response from them will throw any more light on why this might be happening.

  4. #4
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Are you using registered globals in the makenewlist.php file?

    Try defining your submitted fields like this:

    makenewlist.php
    Code:
    <html><head><title>Updating file....</title></head><body> 
    <?php 
    
        $Filename = $_POST['Filename'];
        $Listname = $_POST['Listname'];
    
        $Filename = $Filename . '.lst'; 
        $myfile = fopen('data/lists.txt', 'w'); 
        fputs($myfile, $Listname . '|' . $Filename . "\n"); 
        fclose($myfile); 
    
    ?>Created new list <?php echo $Listname; ?>.<br /> 
    <br /></body></html>

  5. #5
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    That has resolved the result on the submitted fields in the Make a List Form.

    Progressing through the > Add names to an existing list < link we are presented with the following form >

    PHP Code:
    <form method="post" action="saveemail.php">
    <table border="5px" bordercolor="red"><tr><td valign="top">
    <h3>Select a List to<br /> add an e-mail<br /> address to >></h3>
    </td><td><select name="List" size="5px">

    <?php

        $groups 
    file('data/lists.txt');
        for (
    $index 0$index count($groups); $index++) {
            
    $grouplist explode('|'rtrim($groups[$index]));
            echo 
    '<option value="' $grouplist[1] . '"' . (!$index ' selected="selected"' '') . '>' $grouplist[0] . '</option>';
        }

    ?>

    </select></td></tr></table><br />
    Enter an Email Address:<br /><input type="text" name="Email" size="40px">
    <br><br>
    <input type="submit" Value="Add This E-mail to the List">
    </FORM>
    but again a 500 internal server error is presented ?

  6. #6
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    I did not get an error displaying the lists.
    What is the code for saveemail.php ?

  7. #7
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    This is the code for saveemail.php

    PHP Code:
    <html><head>
    <title>Updating file....</title>
    </head><body>
    <br><br>
    <?php
    if (file_exists("data/$List"))
    {
    $myfile file("data/$List");
    $fh fopen("data/$List","w");
    for (
    $index=0$index count($myfile); $index++)
    {
    if (
    $Email != chop($myfile[$index]))
    {
    fputs($fh,$myfile[$index]);}
    }
    fputs($fh,$Email."\n");
    fclose($myfile);
    }
    else
    {
    $myfile fopen("data/$List","w");
    fputs($myfile,$Email."\n");
    fclose($myfile);
    }
    ?>
    <br>
    <?php echo $Email ?> written to <?php echo $List ?>
    <br><br>
    <a href="index.php">Back to Home Page</a>.
    </body></html>

  8. #8
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Ok, similar thing:

    saveemail.php
    PHP Code:
    <html><head>
    <title>Updating file....</title>
    </head><body>
    <br /><br />
    <?php

        $List  
    $_POST['List'];
        
    $Email $_POST['Email'];

        if (
    file_exists("data/$List")) {
            
    $myfile file("data/$List");
            
    $fh fopen("data/$List""w");
            for (
    $index 0$index count($myfile); $index++) {
                if (
    $Email != rtrim($myfile[$index])) {
                    
    fputs($fh$myfile[$index]);
                }
            }
            
    fputs($fh$Email "\n");
            
    fclose($fh);
        } else {
            
    $myfile fopen("data/$List""w");
            
    fputs($myfile$Email "\n");
            
    fclose($myfile);
        }

    ?>
    <br />
    <?php echo $Email?> written to <?php echo $List?>
    <br /><br />
    <a href="index.php">Back to Home Page</a>.
    </body></html>
    Last edited by bionoid; 12-29-2011 at 09:28 AM. Reason: Correction in the code

  9. #9
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Masterful work .... that has broken through that barrier...!

    I shall continue the work through on this and if I should become unstuck again and I probably will, I will be adding to this thread.

    In the meantime is there a simple explanation as to why the information in the scroll box is presented at the bottom of same rather than conventionally at the top? See image attached. Ie it is necessary to scroll down to see the information.
    Attached Images Attached Images

  10. #10
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    You have a few blank items in your data/lists.txt file.
    Just manually edit that file and remove them.

    Code:
    |.lst
    |.lst
    |.lst
    |.lst
    |.lst
    |.lst
    |.lst
    |.lst
    aaaaaaaaa|ssss.lst
    bbbbbbbbbbbb|hhhh.lst
    D List|trial.lst
    Trial2|try.lst
    Trial2|try.lst
    zzzzzzzzzz|write.lst
    zzzzzzzzzz|write.lst
    Last edited by bionoid; 12-29-2011 at 09:23 AM.

  11. #11
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Edited data files so a to go back to the start and start new exercise as earlier it was rushed.

    Created a new list called Tuirtre List and a LST file called Email.lst
    Commenced installing sample email addresses and on submit the 500 error is presented... but the emails do get written to the Email.lst as required

    Why the 500 error and has same any real significance ?

    The inputs into the Email.lst do not happen on each line but are scattered in sequence like the attached image presents.

    Why do the inputs become scattered as shown instead of being laid down line by line ?
    Attached Images Attached Images

  12. #12
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    I had modified the saveemail.php code a number of times.
    Maybe copy-paste the code above again and see if it resolves the issue.

    I was initially appending "\n" to the existing entries, but realised it wasn't necessary.
    Also the original code was closing the incorrect file handle on existing email lists (which would cause an error 500) .
    Last edited by bionoid; 12-29-2011 at 01:26 PM.

  13. #13
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    On progressing to > Edit/Delete names from lists < presents page /picklist.php On selecting Tuirtre List click on > Edit Selected List < introduces page called /editnames.php

    When I edited out all the spaces between the email addresses as shown in the previous image I clicked on > Save This List < and same introduces the page /writenamefile.php

    However, I was expecting to see Changes saved to Emai.lst. but no, all was lost and not saved....! All I get is 'Changes saved to .'

    What appears to have happened is that all the info in the Email.lst was lost and in the list.txt had a double up of info as indicated in the attached image..!
    Attached Images Attached Images

  14. #14
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Quote Originally Posted by webiter View Post
    On progressing to > Edit/Delete names from lists < presents page /picklist.php On selecting Tuirtre List click on > Edit Selected List < introduces page called /editnames.php

    When I edited out all the spaces between the email addresses as shown in the previous image I clicked on > Save This List < and same introduces the page /writenamefile.php

    However, I was expecting to see Changes saved to Emai.lst. but no, all was lost and not saved....! All I get is 'Changes saved to .'

    What appears to have happened is that all the info in the Email.lst was lost and in the list.txt had a double up of info as indicated in the attached image..!
    Umm, yeah. That was my fault, while I was trying to simulate your scenario I accidentally used your form to create a new identical list.

    But using all the code previously submitted I did not get the same errors. I am still certain you are using slightly older code to what is currently in this thread.

    Sorry.

  15. #15
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Yes bionoid, the revised code in the saveemail.php seems to have resolved the 500 issue and the spacing of the sample addresses in the Email.lst.

    When I again entered the editnames.php all the sample emails were on lines as they should be. However when I add another sample email manually and click on > Save This List < all is then lost as I have described before....! The saving is not taking place at this point.
    Last edited by webiter; 12-29-2011 at 02:01 PM. Reason: Removing blank line between paragraphs.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles