Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

internal server error

Status
Not open for further replies.

lenelene

Programmer
Dec 10, 2002
57
0
0
MY
i have one problem.i use cgi to send email but the coding is in perl.when i send enewletter in bulk using the coding, there is error message occur as below stated:

"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, 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. "


why is this happening, the email still can be send despite of this error.why is this error message appear?


this is the coding:

[coding]

use DBI; #the perl database module
use Net::SMTP;

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
else { $INPUT{$name} = $value; }
}

$pid = fork();
print "Content-type: text/html \n\n fork failed: $!" unless defined $pid;

if ($pid) {
my $subject;
my $sender_uid;

$subject = $INPUT{'subject'};
$sender_uid = $INPUT{'sender_uid'};
$sender_uname = $INPUT{'sender_uname'};
$ip = $INPUT['ip'];

# connect to mysql
my $dbh = DBI->connect('DBI:mysql:database=apple:hostname=localhost','appleql','apple');
my $RowAffected = $dbh->do("INSERT INTO apple_mailing_report SET title='$subject',uid='$sender_uid',date=NOW()") or die "Can't connect";
my $log = $dbh->do("INSERT INTO apple_en_activity SET date=now(),time=now(),ip='$ip',login='$sender_uname',activity='Newsletter'") or die "Can't connect";
$dbh->disconnect();

print "Content-type: text/html \n\n";
print "<html>\n";
print "<head>\n";
print " <title>Administration</title>\n";
print " <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n";
print "</head>\n";
print "<body>\n";
print "<br><br><br><center>\n";
print "<table width=\"280\">\n";
print "<tr>\n";
print " <td width=280 valign=top>\n";
print " \n";
print "<table width=\"280\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" bordercolor=\"#808080\" bordercolorlight=\"black\" bordercolordark=\"white\">\n";
print "<tr>\n";
print " <td bgcolor=\"#0000A0\"><font color=\"white\"><b>Send Status</b></td>\n";
print "</tr>\n";
print "<tr>\n";
print " <td bgcolor=\"#C0C0C0\"><br><center>Success!<BR>The message was sent.\n";
print " <P><form><input type=\"button\" value=\"Return\" onClick=\"history.go(-1)\"></form></td>\n";
print "</tr>\n";
print "</table>\n";
print "\n";
print " </td>\n";
print "</tr>\n";
print "</table>\n";
print "</center>\n";
print "</body>\n";
print "</html>";

exit(0);
}
else {
close (STDOUT);

open(LIST,"$INPUT{'address_file'}");
@addresses=<LIST>;
close(LIST);

foreach $line(@addresses) {
chomp($line);
my $ServerName = "relay.apple.com";

# Connect to the server
$smtp = Net::SMTP->new($ServerName);
die "Couldn't connect to server" unless $smtp;

my $MailFrom = $INPUT{'from'};
my $MailTo = $line;

$smtp->mail( $MailFrom );
$smtp->to( $MailTo );

# Start the mail
$smtp->data();

# Send the header.
$smtp->datasend("To: $line\n");
$smtp->datasend("From: $INPUT{'from'}\n");
$smtp->datasend("Subject: $INPUT{'subject'}\n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-Type: text/html\n");
$smtp->datasend("Content-Transfer-Encoding: 7bit\n\n");
$smtp->datasend("<html>\n");
$smtp->datasend("<head>\n");
$smtp->datasend("<title>eHomemaker.net</title>\n");
$smtp->datasend("</head>\n");
$smtp->datasend("<body>\n");

# Send the message
$smtp->datasend("$INPUT{'body'}");
$smtp->datasend("</body>\n");
$smtp->datasend("</html>");
$smtp->datasend("\n\n");

# Send the termination string
$smtp->dataend();
$smtp->quit();
}
}

[/coding]

 
Hmm. Have you tried checking it from the command-line?

perl -c <scriptname>

That might give some hints what's wrong if there is a syntax error in the code.

You might also get that error if you attempt to print something back to the browser before printing the "Content-type" string. You seem to be doing that mostly, but i noticed some "die" clauses that print something without it. It may be that an error is causing one of those die clauses to be triggered, but the missing Content-type is causing an error.

A better approach to handling the Content-type might be to simply print the Content-type right at the beginning of the script, no matter what. Then you won't have to worry about it for the rest of the script; all print and die statements will be covered.

If you check these two things and still get an error, post back and I can look further.

--G
 
i have just solve my problem and i find out because the coding consist of field that is non exist in the database
 
Ah. Yes, that would do it. DBI is not very nice about telling you when something is wrong on the database end - it tends to just quit, kill your script, and leave you to sort it out yourself. Rather unfriendly.

Glad you solved it!

--G
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top