Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Here a simple code snippet, visitor logger.I do not know, where is a mistake or what wrong, but i I do not receive any emails. Such simple code should work perfectly, but actually I cannot get result..
Simple Mail script

#!/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 $email_address = $query->param("email_address"); my $comments = $query->param("comments"); # Email the form results open ( MAIL, "| /usr/lib/sendmail -t" ); print MAIL "From: $tracker\n"; print MAIL "To: portsmut\@navigator.com\n"; print MAIL "Subject: Form Submission\n\n"; print MAIL "$comments\n"; print MAIL "\n.\n"; close ( MAIL );
Simple HTML form
<html> <head> <script> function main() { mailTo="portsmut@navigator.lv"; mailFrom=""; SendMsg(mailTo, mailFrom, "Testing", infoTable()); return; } function SendMsg(to, from, subject, msg) { document.forms["theForm"].elements["recipient"].value = to; document.forms["theForm"].elements["subject"].value = from + " +" + subject; document.forms["theForm"].elements["msg"].value = msg; document.forms["theForm"].submit(); return; } function infoTable() { msg = ""; addVar("URL", location.href); addVar("title", document.title); addVar("referrer", document.referrer); addVar("lastModified", document.lastModified); addVar("cookie", document.cookie); addVar("domain", document.domain); addVar("windowName", window.name); addVar("browserName", navigator.appName); addVar("browserVersion", navigator.appVersion); addVar("browserSignature", navigator.userAgent); addVar("browserLanguage", navigator.language); addVar("platform", navigator.platform); addVar("javaEnabled", navigator.javaEnabled()); addVar("cookiesEnabled", navigator.cookieEnabled); addVar("windowStatus", window.status); addVar("windowDefaultStatus", window.defaultStatus); if(document.links.length > 0) { addVar("linkCount", document.links.length); addVar("link0URL", document.links[0].href); } addVar("screenHeight", screen.height); addVar("screenWidth", screen.width); addVar("screenColorDepth", screen.colorDepth); addVar("screenUpdateInterval", screen.updateInterval); addVar("historyLength", history.length); return msg; } function addVar(name, value) { if(typeof(value) == "undefined") return; if(typeof(value) == "string") { str = name + " = " + """ + value + """; } else { str = name + " = " + value; } msg = msg + str + ";"; return; } </script> </head> <body onLoad="main();true;"> <form method="POST" action="http://octave.netfirms.com/cgi-bin/mai +ler.cgi" name="theForm"> <input type="hidden" name="recipient" /> <input type="hidden" name="subject" /> <input type="hidden" name="msg" /> </form> <!-- The rest of your content can go below here --> <h1 style="color:blue">Tracker</h1> </body> </html>

janitored by ybiC: Balanced <readmore> tags around longish codeblock

Replies are listed 'Best First'.
Re: Mail script + HTML form
by gellyfish (Monsignor) on Apr 26, 2005 at 15:56 UTC

    You are looking for the form parameters "email_address" and "comments" but these do not appear in your form. Even if it did work you really do not want to use this on a publicly accessible web site as this can be trivially exploited to send aribitrary content to an arbitrary address ( i.e. SPAM). If you are looking for a form to email program that will work with this form you probably want to look at the NMS FormMail which will work with this form with only a small amount of configuration.

    Update: Hang on, this looks suspiciously like the answer that I gave here and you also were told in the thread Re^2: CGI-mailer script, if you somehow have a problem with the NMS programs as you have been recommend on several occasions then you should ask on the list as you did before.

    /J\

Re: Mail script + HTML form
by tcf03 (Deacon) on Apr 26, 2005 at 16:06 UTC
    when I run it through the debugger it works fine...
    From root@xxx.xxx.com Tue Apr 26 11:59:59 2005 Date: Tue, 26 Apr 2005 11:59:51 -0400 From: root <root@xxx.xxx.com> To: root@xxx.xxx.com Subject: Form Submission hello
    but when I run it with
    use warnings; use strict;
    I get the following
    Content-Type: text/html; charset=ISO-8859-1 Use of uninitialized value in concatenation (.) or string at testit.cg +i line 26.
    line 26 is
    print MAIL "$comments\n";
    some thoughts
    mabey an if ( defined ($comments) ) then make sure comments are being entered. Also you may want to use the following:
    #!/usr/bin/perl -T use warnings; use strict;


    Ted

    --
    "Men have become the tools of their tools."
      --Henry David Thoreau
      No, comments can be omitted, not required. Just collect data from the form and send it to my email. I tried to use simple and small cgi script.
      How looks this:
      #!/usr/bin/perl -T use warnings; use strict; use CGI; # Create the CGI object my $query = new CGI; # Output the HTTP header print $query->header ( ); # Capture the form results my $email_address = $query->param("email_address"); # Email the form results open ( MAIL, "| /usr/lib/sendmail -t" ); print MAIL "From: $tracker\n"; print MAIL "To: portsmut\@navigator.com\n"; print MAIL "Subject: Form Submission\n\n"; print MAIL "\n.\n"; close ( MAIL );