Results 1 to 5 of 5
  1. #1

    Perl Email List Help

    I'm trying to find some simple perl code that will output an email address from a form into a data file. www.accessoryshoppe.net
    Down in the bottom right hand corner when they type their email in the box and click go, I want it to append their e-mail address to a data file on the webserver for newsletters, and stay on the main page rather than going to a thank you page or whatever. All of the things I found online that do this, ,have admin panels and other things that aren't needed. I just need something very simple. If anyone can help I would greatly appreciate it.

  2. #2
    Join Date
    Sep 2005
    Location
    Cleveland, Ohio
    Posts
    51
    Something like:

    PHP Code:
    #!/usr/bin/perl

    use strict;
    use 
    CGI;

    my $cgi CGI->new();

    if ( 
    $cgi->param'emailAddress' ) )
    {
          
    open OUTPUT">>email.txt" ) or die "Can't open email list: $!\n";
          print 
    OUTPUT "$cgi->param( 'emaiAddress' )\n";
          
    close OUTPUT );
    }

    exit; 
    though you'll probably want to add some file locking to the above... especially if you're on a site with moderate to heavy usage.
    Jim Lundeen
    Edgar Technologies

    Professional Small Business IT Management
    http://edgar-tech.com

  3. #3
    It didn't add anything to email.txt and it gave a 500 Internal Server Error.

  4. #4
    Join Date
    Sep 2005
    Location
    Cleveland, Ohio
    Posts
    51
    The code was only meant to be an example. It isn't something you would want to put into production by itself.

    The reason the email.txt is empty is that I had a typo "emaiAddress" should be "emailAddress". Currently, your file is probably full of blank lines.

    Make sure you CHMOD your script file to 0755 or 0777. And add a Location redirect before the exit command, pointing the script back to the page it was called from.
    Jim Lundeen
    Edgar Technologies

    Professional Small Business IT Management
    http://edgar-tech.com

  5. #5
    Join Date
    May 2001
    Location
    HK
    Posts
    3,076

    Smile

    No header was sent, that was why you were getting a 500.
    Either print the header or use 'Location' to bring the user to another page.

    Code:
    print $cgi->header(-type=>'text/html');
    print "Your emeow has been added\n";
    Code:
    print $cgi->redirect('http://www.yoursite.com/somepage.html');
    Chmod 0777 is not a good idea and suexec may not work for that if you have suexec enabled ~ 0755 sounds good ~

Posting Permissions

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