Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script check !!!

    Hi eveyone,

    I was just wandering if someone could look at this script and tell me if there is anything wrong with it. I have it on my site, when i sumbit the form its attached to, it doesn't give me any errors and then redirects me to the page it should. But it doesn't appear to be generating any e-mails, cause none have come through.

    Anyway can you see if there is anything wrong with it.

    Thanks

    #!/usr/local/bin/perl - w

    #--------------------------------------------------------------------------------
    #--------------------------------------------------------------------------------
    # CGI SCRIPT FOR PROCESSING THE E-MAIL FORM ON OUR WEBSITE
    #--------------------------------------------------------------------------------
    #--------------------------------------------------------------------------------

    #Location of sendmail on server
    $MailProgram = '/usr/sbin/sendmail-t';

    #Email address to use for sending results
    $OurEmail = 'ourmail@ourcompany.co.uk';

    sub ErrorHTML {
    #Error handler
    my $eh = join '<li>',@_;
    print "Content-type: text/html\n\n";
    print qq~
    <html>
    <head>
    <title>Notice : Error</title>
    </head>
    <body>
    <h4>Notice:</h4><ul><li>$eh</ul>
    </body>
    </html>
    ~;
    exit;
    }

    #-------------------------------------------------------------------------------------
    #STARTS PROCESSING THE FORM DATA HERE
    #-------------------------------------------------------------------------------------

    sub Parse {
    #Parse form submission sent by user
    my $buffer;
    ErrorHTML('Form must use method "POST"') unless ($ENV{REQUEST_METHOD} eq 'POST');
    read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
    my @data = split(/&/,$buffer);
    for(@data) {
    $_ =~ tr/+/ /;
    my ($n,$v) = split(/=/,$_);
    $n =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    $v =~ s/\<(.*?)embed/\<$1\_e_m_b_e_d_\(mailer_robot_edited\)/sig;
    $v =~ s/\<(.*?)object/\<$1\_o_b_j_e_c_t_\(mailer_robot_edited\)/sig;
    $v =~ s/\<(.*?)script/\<$1\_s_c_r_i_p_t_\(mailer_robot_edited\)/sig;
    $v =~ s/\<(.*?)applet/\<$1\_a_p_p_l_e_t_\(mailer_robot_edited\)/sig;
    $fields{$n} = $v;
    }
    }

    #--------DISCARDS EXTRA SPACES FROM THE FORM INPUT-------------------------------------

    sub DiscardExtraSpaces {
    my $s=$_[0];
    $s=~s/\A\s+//;
    $s=~s/\s+\Z//;
    $s=~s/\s\s+/ /g;
    return $s;
    }


    #-------INITIATES PARSE FUNCTION-------------------------------

    Parse;

    #-------STARTS TO WRITE THE EMAIL----------------------------------------------------

    $MailProgram .= ' -t' if $MailProgram =~ /sendmail\Z/;
    $fields{FirstName} = DiscardExtraSpaces($fields{FirstName});
    $subject = 'Website feedback form submission';

    open MAIL,"|$MailProgram";
    print MAIL <<TO_END;
    To: $OurEmail
    From: $fields{EMail} <"$fields{FirstName}""$fields{LastName}">
    Subject: $subject
    Content-Type: text/plain; charset="us-ascii"

    Title: $fields{title}
    First Name: $fields{FirstName}
    Last Name: $fields{LastName}
    Telephone: $fields{Telephone}
    E-mail: $fields{EMail}
    Topic: $fields{Topic}
    ------------------------------------------------------------
    Comments: $fields{Comments}

    ------------------------------------------------------------
    ------------------------------------------------------------
    IP: $ENV{REMOTE_ADDR}
    Form: $ENV{HTTP_REFERER}
    ------------------------------------------------------------
    ------------------------------------------------------------
    TO_END

    close MAIL;

    print "Location: http://www.oursite.co.uk\n\n" ;

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    Can someone please take a look at this. Im kind of desperate, as I need it working. Just see if there is any reason why it should not work ??

    Thanks

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Moscow, RU
    Posts
    23
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hello,

    the first thing i noted:
    $MailProgram = '/usr/sbin/sendmail-t';
    which is completely wrong -
    $MailProgram = '/usr/sbin/sendmail -t';

    other thing i noted:
    $MailProgram .= ' -t' if $MailProgram =~ /sendmail\Z/; # This line adding ' -t ' to sendmail when it's just /usr/sbin/sendmail - but you have defined your sendmail with -t at the top why to add this line?

    hope this will help you

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    woooohhhhhhhhoooooooooooooo

    Yes thankyou Inci

    Your brilliant. That fixed it. Ah thankyou so much man, I really really appreaciate it.

    wooooohhhhhhhooooooooooooooooooo

    Thankyou


  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi everyone,

    I was just wandering if it is possible to add an autorespond function to this script. After the form details have been sent to us, an e-mail is then sent out using the e-mail field as the 'to' value.

    Any ideas on this ??

    Thanks

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could just reuse the same mail-sending code again, just with different parameters.

  • #7
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I have tried that but it dosen't work. It will send the form data to our e-mail, but its not generating the autoreply.

    Any ideas on why its not doing it ??

    Here is the code I have got:

    #!/usr/local/bin/perl -w

    #--------------------------------------------------------------------------------
    #--------------------------------------------------------------------------------
    # CGI SCRIPT FOR PROCESSING THE E-MAIL FORM ON OUR WEBSITE
    #--------------------------------------------------------------------------------
    #--------------------------------------------------------------------------------

    #Location of sendmail on server
    $MailProgram = '/usr/sbin/sendmail -t';

    #Email address to use for sending results
    $OurEmail = 'ourmail@oursite.co.uk';

    sub ErrorHTML {
    #Error handler
    my $eh = join '<li>',@_;
    print "Content-type: text/html\n\n";
    print qq~
    <html>
    <head>
    <title>Notice : Error</title>
    </head>
    <body>
    <h4>Notice:</h4><ul><li>$eh</ul>
    </body>
    </html>
    ~;
    exit;
    }

    #-------------------------------------------------------------------------------------
    #STARTS PROCESSING THE FORM DATA HERE
    #-------------------------------------------------------------------------------------

    sub Parse {
    #Parse form submission sent by user
    my $buffer;
    ErrorHTML('Form must use method "POST"') unless ($ENV{REQUEST_METHOD} eq 'POST');
    read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
    my @data = split(/&/,$buffer);
    for(@data) {
    $_ =~ tr/+/ /;
    my ($n,$v) = split(/=/,$_);
    $n =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    $v =~ s/\<(.*?)embed/\<$1\_e_m_b_e_d_\(mailer_robot_edited\)/sig;
    $v =~ s/\<(.*?)object/\<$1\_o_b_j_e_c_t_\(mailer_robot_edited\)/sig;
    $v =~ s/\<(.*?)script/\<$1\_s_c_r_i_p_t_\(mailer_robot_edited\)/sig;
    $v =~ s/\<(.*?)applet/\<$1\_a_p_p_l_e_t_\(mailer_robot_edited\)/sig;
    $fields{$n} = $v;
    }
    }

    #-------INITIATES CHECK AUTHORIZED AND PARSE FUNCTION-------------------------------

    Parse;

    #-------STARTS TO WRITE THE EMAIL----------------------------------------------------

    $subject = 'Website request for brochure';

    open MAIL,"|$MailProgram";
    print MAIL <<TO_END;
    To: $OurEmail
    From: $fields{EMail} <"$fields{FirstName}""$fields{LastName}">
    Subject: $subject
    Content-Type: text/plain; charset="us-ascii"

    ------------------------------------------------------------
    Title: $fields{title}
    First Name: $fields{FirstName}
    Last Name: $fields{LastName}
    Address: $fields{Address}
    Town: $fields{Town}
    County: $fields{County}
    Postcode: $fields{Postcode}
    Number: $fields{Telephone}
    E-mail: $fields{EMail}

    ------------------------------------------------------------
    ------------------------------------------------------------
    IP: $ENV{REMOTE_ADDR}
    Form: $ENV{HTTP_REFERER}
    ------------------------------------------------------------
    ------------------------------------------------------------
    TO_END

    close MAIL;

    #--------Autoresponder----------------------------------------------------------

    open MAIL,"|$MailProgram";
    print MAIL <<TO_END;
    To: $fields{EMail}
    From: $OurEmail
    Subject: Autoresponder
    Content-Type: text/plain; charset="us-ascii"

    ------------------------------------------------------------
    The body of the e-mail autoresponder is written here

    ------------------------------------------------------------
    TO_END

    close MAIL;

    print "Location: http://www.oursite.co.uk\n\n";

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Worked fine for me... are you sure you've got the TO_END markers on a line by themselves with nothing like spaces immediately after?

    Also I didn't check, but I got rid of it for testing, but perhaps the script is throwing up warnings..? Hmm... they'd probably get printed to the errorlog anyway..

    I didn't use any forms though, I just hardcoded some values in.

  • #9
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No it still doesn't work. I checked for any extra spaces and that and it was fine. Its got to be something to do with the autorespond bit. Thats the only bit not being generated.

    Any more ideas anyone ??

    Thanks


  •  

    Posting Permissions

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