www.webdeveloper.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 37

Thread: Running Mail List Tutorial...!

  1. #16
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    What is the code for writenamefile.php ?

  2. #17
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Here is the code for the writenamefile.php

    PHP Code:
    <html><head>
    <title>Updating file....</title>
    </head><body>
    <br><br>
    Changes saved to <?php echo $List ?>.<br>
    <?php
        $List  
    $_POST['List'];
        
    $myfile fopen("data/$List","a");
        
    fputs($myfile,$Body);
        
    fclose($myfile);
    ?>
    <br>
    <a href="index.php">Back to Home Page.</a>
    </body></html>

  3. #18
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Thanks.

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

        $List 
    $_POST['List'];
        
    $Body $_POST['Body'];

        
    $myfile fopen("data/$List"'w');
        
    fputs($myfilertrim($Body) . "\n");
        
    fclose($myfile);

    ?>
    Changes saved 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 02:45 PM.

  4. #19
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by bionoid View Post
    Thanks.

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

        $List 
    $_POST['List'];
        
    $Body $_POST['Body'];

        
    $myfile fopen("data/$List"'w');
        
    fputs($myfilertrim($Body) . "\n");
        
    fclose($myfile);

    ?>
    Changes saved to <?php echo $List?>.<br /><br />
    <a href="index.php">Back to Home Page.</a>
    </body></html>
    I might be mistaken but at first glance it looks like "$myfile" might need the same treatment as "list" and "body"?

  5. #20
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Quote Originally Posted by criterion9 View Post
    I might be mistaken but at first glance it looks like "$myfile" might need the same treatment as "list" and "body"?
    You are mistaken, $myfile is the resulting file handle for the fopen function. Unless I am also mistaken about you being mistaken?
    Last edited by bionoid; 12-29-2011 at 03:17 PM.

  6. #21
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    My connection is hopeless for the past hours as network is probably very busy.
    writenamefile.php is now saving as required to Email.lst

    I will add here the sendmail.php just in case it needs attention/updating and revert tomorrow. Hope the temp connection transmits.

    PHP Code:
    <html><head>
    <title>Updating file....</title>
    </head><body>
    <?php
        $addresses 
    file("data/$List");
        for (
    $index=0$index count($addresses); $index++)
        {                                                 
        
    mail("$addresses[$index]","$Subject",
        
    "$Body","From: $From\nReply-To: $From");
        }
        
    $myfile fopen("data/log.txt","a");
        
    fputs($myfile,$Subject."\t".date("dS of F Y h:i:s A")."\t".$List."\n");
        
    fclose($myfile);  
    ?>
    Your message was sent!
    <br><br>
    <a href="index.php">Back to Home Page</a>.
    </body></html>

  7. #22
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    I didn't test this one, but I'm sure it works the same way:

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

        $List    
    $_POST('List');
        
    $From    $_POST('From');
        
    $Subject $_POST('Subject');
        
    $Body    $_POST('Body');

        
    $addresses file("data/$List");
        for (
    $index 0$index count($addresses); $index++) {
            
    mail(rtrim($addresses[$index]), $Subject$Body"From: $From\nReply-To: $From");
        }
        
    $myfile fopen('data/log.txt''a');
        
    fputs($myfile$Subject "\t" date('dS of F Y h:i:s A') . "\t" $List "\n");
        
    fclose($myfile);

    ?>
    Your message was sent!
    <br /><br />
    <a href="index.php">Back to Home Page</a>.
    </body></html>

  8. #23
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by bionoid View Post
    You are mistaken, $myfile is the resulting file handle for the fopen function. Unless I am also mistaken about you being mistaken?
    No you got it. I was seeing myfile used but I was skipping over the line where it was created. Sorry about that.

  9. #24
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Quote Originally Posted by criterion9 View Post
    No you got it. I was seeing myfile used but I was skipping over the line where it was created. Sorry about that.
    No harm done. I have been able to test most of the code submitted so I was fairly confident

  10. #25
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Thanks bionoid,
    sendmail.php code tidied up but I have not taken that further yet...!

    Have set up a test Subscribe link facility on the index.php page.

    Presenting these last few .php file pages in package for review:

    Placing them all together as my internet link remains poor this morning.

    This is the thanks.php page code:

    PHP Code:
    <html><head>
    <title>Thanks You Page</title>
    </head><body>
    <?php

        $Body 
    =  readfile("data/autoresponder.txt");        
        
    mail("$Email","Welcome to my mailing list!",
        
    "$Body","From: Me\nReply-To: me@myaddress.com");
        
    $myfile file("data/mylist.lst");
        
    $fh fopen("data/mylist.lst","a");
        for (
    $index=0$index count($myfile); $index++)
        {
        if (
    $Email != chop($myfile[$index]))
        {
    fputs($fh,$myfile[$index]);}
        }
        
    fputs($fh,$Email."\n");
        
    fclose($myfile);

    ?>
    Thank you!
    <br><br>
    <a href="index.php">Back to Home Page</a>.
    </body></html>

    the autoresponder.php code

    PHP Code:
    <html><head><title>Edit Autoresponder Messages</title></head><body>
    <form method="post" action="writeautoresponder.php">
    <br />
    <h3>Autoresponder Message</h3>
    This is the automatic message that will be sent<br /> 
    to people who have submitted their Email address <br />
    to the mailing list.
    <br><br>
    <textarea cols="40" rows="10" name="Body">
    <?php

        readfile
    ("data/autoresponder.txt");
        
    ?>
    </textarea>
    <br><br>
    <input type="submit" name="submit" value="Save This Auto Message"></FORM>
    <br><br><a href="addnames.php">Add E-mails to a list</a>.
    <br><br><a href="data/log.txt">View the Send Log</a>.
    <br>
    </body></html>
    and the writeautoresponder.php

    PHP Code:
    <html><head>
    <title>Updating file....</title>
    </head><body>
    <br><br>
    <b>The following autoresponder message has been saved:</b><br>
    <?php

        $myfile 
    fopen("data/autoresponder.txt","a");
        
    fputs($myfile,$Body);
        
    fclose($myfile);

    ?>
    <br>
    <pre><?php echo $Body ?> </pre><br>
    <br>
    <a href="index.php">Back to Home Page.</a>
    </body></html>
    Additional Info: Using the Subscribe.html in Wamp presents the 'Thank you!' message. On the live server it presents with a 500 error...!
    Last edited by webiter; 12-30-2011 at 09:19 AM. Reason: Added additional info at bottom of page...

  11. #26
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Using subscribe.html sample at this position to enable a visitor to add a validated email to a list.

    Currently using a Drop-in box (DynamicDrive type) to thank visitor for submission and advise them that their email will be added to the List.

    Have opened writesubscription.php as the action on "myForm" in subscribe.html so as to facilitate writing of the submitted email to the List.

    The writesubscription.php is as follows:


    PHP Code:
    <html><head>
    <title>Write Sub to List....</title>
    </head><body>
    <?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);
        }

    ?>
    </body></html>
    On the server it does not add to list..! Advises of 500 internal error. This page seems almost identical to the saveemail.php that works when inputting emails from the Admin Panel.

    Why does this not work in the new situation and is this approach proper use of logic on my behalf??

  12. #27
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    You are not sending which list the email address should be inserted into in the form:

    subscribe.html
    Code:
    <form name="myForm" action="writesubscription.php" onsubmit="return validateForm();" method="post">
    	<input type="hidden" name="List" value="???????.lst" />
    	Email: <input type="text" name="Email" size="25" />
    	<br /><br />
    	<input type="submit" value="Submit E-mail to List" />
    </form>
    writesubscription.php
    Code:
    <html><head> 
    <title>Write Sub to List....</title> 
    </head><body> 
    <?php 
    
        $List  = $_POST['List']; //ERROR
        $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); 
        } 
    
    ?> 
    </body></html>
    JavaScript: Learn | Validate | Compact | bionoid

  13. #28
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    This is not always fun! Yes, now resolved the issue with the missing line in the subscribe.html and thing performed as required sending sample subscribed emails to the List. Yes, there is a reason for everything.

    When installing message in autoresponder.php it gets processed by the writeautoresponder.php. In my trials it will not save to the autresponder.txt...!
    I have tried different things including the a, the w and $Body = $_POST('Body'); all to no effect...!

    This is the autoresponder.php

    PHP Code:
    <?php

        readfile
    ("data/autoresponder.txt");
        
    ?>
    and this is the writeautosponder.php

    PHP Code:
    <b>The following autoresponder message has been saved:</b><br>
    <?php

        $myfile 
    fopen("data/autoresponder.txt","a");
        
    fputs($myfile,$Body);
        
    fclose($myfile);

    ?>
    <br>
    <pre><?php echo $Body ?> </pre><br>
    Any ideas on the fix required!

  14. #29
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    The code you submitted for autoresponder.php doesn't seem right. The data/autoresponder.txt file is blank yet it still produces a form?

    And in that form is only the Body field that is of any interest, so the only field to pull from the post should be $Body:

    Code:
    <b>The following autoresponder message has been saved:</b><br />
    <?php
    
    	$Body = $_POST['Body'];
    
    	$myfile = fopen('data/autoresponder.txt', 'a');
    	fputs($myfile, $Body);
    	fclose($myfile);
    
    ?>
    <br />
    <pre><?php echo $Body; ?> </pre><br />
    Remember square brackets to access array members [], and round brackets for functions.
    Last edited by bionoid; 12-31-2011 at 12:23 PM.
    JavaScript: Learn | Validate | Compact | bionoid

  15. #30
    Join Date
    Jul 2011
    Location
    Irish Republic
    Posts
    64
    Having a problem grasping the logic. No, I did not have anything to drink over the New Year. Happy New Year. Back to the logic bit!

    Firstly, When a visitor submits an email address it is written to the List with the writesubscription.php I was of the opinion that a message would then be sent to the visitors email address from the autoresponder facility and that this would happen automatically after the visitor submitted the email address.! Is this correct thinking in respect of the autoresponder facility and how would/is same activated?

    Secondly, I had formed the opinion that I was now at the point where using the index.php page that I could send a test message (as in a update) to the emails in the email list..! The test message is subject to processing by the sendmail.php but nothing only a 404 gets delivered!

    again the sendmail.php is:

    PHP Code:
    <?php

        $List    
    $_POST('List');
        
    $From    $_POST('From');
        
    $Subject $_POST('Subject');
        
    $Body    $_POST('Body');

        
    $addresses file("data/$List");
        for (
    $index 0$index count($addresses); $index++) {
            
    mail(rtrim($addresses[$index]), $Subject$Body"From: $From\nReply-To: $From");
        }
        
    $myfile fopen('data/log.txt''a');
        
    fputs($myfile$Subject "\t" date('dS of F Y h:i:s A') . "\t" $List "\n");
        
    fclose($myfile);

    ?>
    Your message was sent!

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