Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple Form Mailer

Options
  • 19-03-2008 12:45am
    #1
    Closed Accounts Posts: 121 ✭✭


    Hi - Okay ive got a simple enough website going. I have a page on the site to contact the owner or leave feedback etc which gets emailed to him.

    Trouble is im getting an internal server error when i hit the submit button.

    So here's the code I've got:

    The HTML Feedback Page (form part)
    <FORM action="/cgi-bin/cgiemail.cgi" method="post">
    Name:
    <input type="text" name="contactname"><br><br>
    Phone Number:
    <input type="text" name="phonenum">
    E-Mail Address:
    <input type="text" name="email">
    E-Mail
    <input type="checkbox" name="emailchkbox" value="E-Mail">
    Phone
    <input type="checkbox" name="phonenumchkbox" value="Phone">
    Both
    <input type="checkbox" name="bothchkbox" value="Both">
    Comments/Questions:
    <textarea name="comqs" rows="7" cols="60">
    </textarea>
    
    <input type="submit" value="Send">
    <input type="reset">
    
    </form>
    
    >

    Okay - so ive got the HTML file in the public_html folder.
    And the 'cgiemail' script which is supplied on the server is in /public_html/cgi-bin

    Then I've got this perl file too and im not sure what to do with this. The perl location on the server is usr/bin/perl
    #!/usr/bin/perl
    
    use CGI;
    
    # Create the CGI object
    my $query = new CGI;
    
    # Output the HTTP header
    print $query->header ( );
    
    # Capture the form results
    my $contactname = $query->param("contactname");
    my $phonenum = $query->param("phonenum");
    my $email = $query->param("email");
    my $emailchkbox = $query->param("emailchkbox");
    my $phonenumchkbox = $query->param("phonenumchkbox");
    my $bothchkbox = $query->param("bothchkbox");
    my $comqs = $query->param("comqs");
    
    # Filter the form results
    $email = filter_header_field ( $email );
    $comqs = filter_field ( $comqs );
    $contacname = filter_field ( $contactname );
    $phonenum = filter_field ( $phonenum );
    $emailchkbox = filter_field ( $emailchkbox );
    $phonenumchkbox = filter_field ( $phonenumchkbox );
    $bothchkbox = filter_field ( $bothchkbox );
    
    # Email the form results
    open ( MAIL, "| /usr/lib/sendmail -t" );
    print MAIL "Name: $email\n";
    print MAIL "Email Address: $email\n";
    print MAIL "Phone Number: $phonenum\n";
    print MAIL "Contact Me By: $emailchkbox\n";
    print MAIL "Contact Me By: $phonenumchkbox\n";
    print MAIL "Contact Me By: $bothchkbox\n";
    print MAIL "Comments/Message: $comqs\n";
    print MAIL "To: info@mysite.com\n";
    print MAIL "Subject: My Site Form Submission\n\n";
    print MAIL "$comqs\n";
    print MAIL "\n.\n";
    close ( MAIL );
    
    # Thank the user
    print <<END_HTML;
    <html>
    <head></head>
    <body>Thank you. We will be in touch within 24hrs.!</body>
    </html>
    END_HTML
    
    # Functions for filtering user input
    
    sub filter_field
    {
      my $field = shift;
      $field =~ s/From://gi;
      $field =~ s/To://gi;
      $field =~ s/BCC://gi;
      $field =~ s/CC://gi;
      $field =~ s/Subject://gi;
      $field =~ s/Content-Type://gi;
      return $field;
    }
    
    sub filter_header_field
    {
      my $field = shift;
      $field =~ s/From://gi;
      $field =~ s/To://gi;
      $field =~ s/BCC://gi;
      $field =~ s/CC://gi;
      $field =~ s/Subject://gi;
      $field =~ s/Content-Type://gi;
      $field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
      return $field;
    }
    

    Any help is appreciated - thanks!
    Thanks


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    What's the server error?


  • Closed Accounts Posts: 121 ✭✭Puff Puff Pass


    Here's the error
    Internal Server Error
    
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    
    Please contact the server administrator, webmaster@mysite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    
    More information about this error may be available in the server error log.
    
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Well it looks like the perl file is the code for the cgiemail script. Dunno much about perl though, is there an error log on the server? It may tell you exactly what went wrong.


  • Closed Accounts Posts: 121 ✭✭Puff Puff Pass


    ye there is - i'll check that later

    ye i know a few languages but perl and cgi dont come into it


  • Closed Accounts Posts: 121 ✭✭Puff Puff Pass


    Got it working. I had the form action incorrect.

    the format should be

    http://yoursitename.com/cgi-bin/cgiemail/emailtemplate.txt

    where cgi-bin is the location of yout cgi email script and cgiemail is the name of the script and emailtemplate.txt is the layout of the email that is to be sent which includes the variables from the html form


  • Advertisement
Advertisement