malformed header from script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madevo8
    New Member
    • Feb 2008
    • 4

    malformed header from script

    Hi All

    I am getting a 500 internal server error plus the below message in my log file when trying to execute a script.

    Code:
    malformed header from script. Bad header=/home/fhlinux159/f/*domain*: /home/fhlinux159/f/*domain*.co.uk
    /user/htdocs/cgi-bin/orderNZ.cgi
    I am pretty useless in CGI to be honest, and didn't write the script in question :S any help would be much appreciated.

    Thanks
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    if the script is not too long post it into a reply. Use the code tags please.

    Comment

    • Kelicula
      Recognized Expert New Member
      • Jul 2007
      • 176

      #3
      Also make sure that you change the permissions of the file.
      CHMOD 755

      Comment

      • madevo8
        New Member
        • Feb 2008
        • 4

        #4
        Hi Again

        I have done some more digging and stopped the initial error I was getting, however I now get the below text printed at the top of the page and the 2 emails I expect to be sent are not coming through...

        Code:
        /home/fhlinux159/f/*domain*.co.uk/user/dead.letter... Saved message in /home/fhlinux159/f/friezeframe.co.uk/user/dead.letter 
        /home/fhlinux159/f/*domain*.co.uk/user/dead.letter... Saved message in /home/fhlinux159/f/*domain*/user/dead.letter Content-Type: text/html; charset=ISO-8859-1
        Is this some kind of authentication problem or something else?

        I believe the below lines of code are responsible for creating the emails if this helps...

        Code:
        open( 	FF_MAIL_HANDLE, "|/usr/sbin/sendmail -t -oi") or dienice("Can't fork for sendmail. Error: $!");
        print 	FF_MAIL_HANDLE "From: $from\n";
        print 	FF_MAIL_HANDLE "To: $ff_recipient\n";
        print 	FF_MAIL_HANDLE "Bcc: $bcc\n";
        print 	FF_MAIL_HANDLE "Content-Type: text/html\n";
        print 	FF_MAIL_HANDLE "Subject: $subject\n\n";
         
         
        open( 	CUST_MAIL_HANDLE, "|/usr/sbin/sendmail -t -oi") or dienice("Can't fork for sendmail. Error: $!");
        print 	CUST_MAIL_HANDLE "From: $from\n";
        print 	CUST_MAIL_HANDLE "To: $cust_recipient\n";
        print 	CUST_MAIL_HANDLE "Bcc: $bcc\n";
        print 	CUST_MAIL_HANDLE "Content-Type: text/html\n";
        print 	CUST_MAIL_HANDLE "Subject: $subject\n\n";
         
         
        # Send the HTML headers to the browser - dont need to bother when sending an email
        print 	header;
         
         
         
         
        print <<END_HTML_A;
        	<head>
        		<title> etc etc........

        Comment

        • Kelicula
          Recognized Expert New Member
          • Jul 2007
          • 176

          #5
          Well you will need to close those open filehandles. But I assume you do that later on.

          Also I noticed that you never sent the "body" of the message.

          Personally I wouldn't have two forks to sendmail opened at the same time.
          Are they interdependent?

          Try opening each mail one at a time, then sending, then closing. Then open next one...etc..

          One more thing.
          The "content-type: text/html\n" needs to have two line breaks to signify end of content type header.

          Try moving that into the first line of the "body" of the email.

          [code=perl]

          open( FF_MAIL_HANDLE, "|/usr/sbin/sendmail -t -oi") or dienice("Can't fork for sendmail. Error: $!");
          print FF_MAIL_HANDLE "From: $from\n";
          print FF_MAIL_HANDLE "To: $ff_recipient\n ";
          print FF_MAIL_HANDLE "Bcc: $bcc\n";
          print FF_MAIL_HANDLE "Subject: $subject\n\n";
          # The above double line break signifies beginning of message body.
          # Or more accurately END of mail headers..


          print FF_MAIL_HANDLE "Content-Type: text/html\n\n";
          print FF_MAIL_HANDLE "This will be the message content...";

          close(FF_MAIL_H ANDLE);
          [/code]

          What is your reason for setting the content type to html for the email?
          Most email clients nowadays will translate hyperlinks and images etc... automatically for you.

          One last thing.
          You can use here document for the mail output also.
          example:

          [code=perl]
          open( FF_MAIL_HANDLE, "|/usr/sbin/sendmail -t -oi") or dienice("Can't fork for sendmail. Error: $!");
          print FF_MAIL_HANDLE <<EMAIL;
          From: $from\n
          To: $ff_recipient\n
          Bcc: $bcc\n
          Subject: $subject\n\n

          Content-Type: text/html\n\n
          This will be the message content...\n

          EMAIL

          close(FF_MAIL_H ANDLE);
          [/code]
          Last edited by Kelicula; Mar 7 '08, 11:10 PM. Reason: here document.

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            You don't need the newlines if you use the heredoc

            Comment

            • madevo8
              New Member
              • Feb 2008
              • 4

              #7
              Hi Guys

              First of all, I am no longer getting the lines of code at the top of the browser output page anymore which may be down to the hosts changing a setting of some sort on the server as I have emailed them about this but I am not entirely sure.

              The emails are only coming through to hotmail addresses which is very odd but I thought maybe it was indeed down to the Content-Type header line being in the wrong place as Kelicula suggested, so I tried moving that to the top of the body of the email but it stopped the email from showing as html and just printed the 'Content-Type: text/html' at the top of the email followed by the html code.

              I can't really change to using the heredoc method easily as there are many lines of code which produce the body of each email based on what was submitted.

              I am confused/frustrated :(

              Thanks for your help so far...

              Comment

              • Kelicula
                Recognized Expert New Member
                • Jul 2007
                • 176

                #8
                Read this:


                Also notice these issues.

                ~~ The email's size is larger than it would be if only
                one or the other format is used. Some people are
                sensitive to email size, those who pay for the time
                they use their Internet connection, for example.
                And some people automatically block larger email
                because spam is often delivered in larger emails.

                ~~ A few email programs will display both the text and
                the HTML portion, the latter with codes and all.

                You should have been able to send html emails, with the last example though. ??

                Maybe the site has something restricted?
                Have you heard back from them?

                You can use info, as in variables within a heredoc.
                You can also select what type of quote character is used to quote the elements
                within the heredoc like so:
                [code=perl]
                use strict;

                my $value = "Foo";

                my $heredoc = <<"END";
                Hey there!
                Everything within here will be quoted in "double-quotes".
                But notice that I can also use double quotes in here, and they automatically
                get escaped.

                Variables are interpolated.
                $value will become "Foo".

                Yea!!

                END

                # Or use single quotes

                my $heredoc2 = <<'END';
                All this is single quoted.
                Variables are NOT interpolated.
                Boo..

                END

                # Or use an arbitrary character

                my $heredoc3 = <<*END*;
                Everything in here is quoted in asterisks.
                Who knows what happens.

                END
                [/code]

                Good Luck!

                Comment

                • madevo8
                  New Member
                  • Feb 2008
                  • 4

                  #9
                  Hi Again

                  My hosts have finally come back to me and explained that it was an authentication problem and that I had to put a -f switch after declaring the sendmail.

                  Sorted at last!

                  Thanks for your help guys

                  Comment

                  Working...