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 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    71
    Thanks
    9
    Thanked 3 Times in 3 Posts

    mail script doesn't send email - no errors

    ok, I have a new problem (still waiting on a answer to my previous thread). I have a sendmail script that is not working, but is not generating any errors either. I have searched everywhere I can for an answer, but cannot find anything on this. What little I have found, I tried to no avail. Maybe someone here can help.

    Code:
    #!/usr/bin/perl -w
    
    use strict;
    use CGI;
    use CGI::Carp qw ( fatalsToBrowser );
    use File::Basename;
    
    #$CGI::POST_MAX = 1024 * 5000;
    my $safe_filename_characters = "a-zA-Z0-9_.-";
    my $upload_dir = "/httpd/htdocs/download/";
    
    my $query = new CGI;
    my $filename = $query->param("ufile");
    my $uname = $query->param("name");
    my $comment = $query->param("com");
    
    if ( !$filename )
    {
     returnStatus ("'No file specified'");
     exit;
    }
    
    my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
    $filename = $name . $extension;
    $filename =~ tr/ /_/;
    $filename =~ s/[^$safe_filename_characters]//g;
    
    if ( $filename =~ /^([$safe_filename_characters]+)$/ )
    {
     $filename = $1;
    }
    else
    {
     die "Filename contains invalid characters";
    }
    
    my $upload_filehandle = $query->upload("ufile");
    
    open ( UPLOADFILE, ">$upload_dir/$filename" ) or returnStatus ("'Could not upload file!'");
    binmode UPLOADFILE;
    
    while ( <$upload_filehandle> )
    {
     print UPLOADFILE;
    }
    close UPLOADFILE;
    
    open (MAIL, "|/usr/sbin/sendmail -t") or diemail ("'Cannot access mailer!'");
    print MAIL "From: $uname\n";
    print MAIL "To: me\@here.com\n";
    #real email changed
    print MAIL "Subject: File upload\n\n";
    print MAIL "Content-type: text/plain\n\n";
    print MAIL "$uname just uploaded the file $filename.\n";
    print MAIL "$comment\n";
    print MAIL "\n.\n";
    close (MAIL);
    
    returnStatus ("'File uploaded successfully'");
    
    sub returnStatus {
        my $status = shift;
        print "Content-type: text/html\n\n";
        print <<EOJS;
        <html>
        <body><script type='text/javascript'>function init(){if(top.uploadComplete)
        top.uploadComplete($status);}window.onload=init;</script></body>
        </html>"
    EOJS
    ;
    }
    
    sub diemail {
        my $msg = shift;
        print "Content-type: text/html\n\n";
        print <<END_HTML;
        <html>
        <body><script type='text/javascript'>function init(){if(top.uploadComplete)
        top.uploadComplete($msg);}window.onload=init;</script></body>
        </html>"
    END_HTML
    ;
    }
    The file uploads correctly, and the correct message is displayed on my html page when the upload is complete, it's just the sendmail portion that is not working.

    I have checked the error log and found nothing. I checked the syntax with perl and it is correct and I have verified that my email address is correct and working. I get no errors in the Firefox error console either. I checked the server for the correct location of sendmail using 'which sendmail'. Can anyone think of anything else I can check?

    What's really weird is I am using this same portion of the script in another cgi on my site and the email is working fine there. I have checked line by line to make sure I did not leave anything out and it is all correct. The only difference is the fact that this script (the non working one) is called from a page that is protected by .htaccess.
    It's OK to pee against the wind if your standing in a lake.

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    mail program woes

    FWIW
    RE: SENDMAIL:
    my host requires a valid eMail in the open mail string,
    in this case it's the mail sent to my editor.
    open( MAIL, "|$mailprog editor\@samedomainhostingtheform.com" )

    When it's the mail sent to a form submitting address,
    I insert $FORM{ 'email' )

    HTH


  •  

    Posting Permissions

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