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!

email not being sent

Status
Not open for further replies.
Apr 12, 2004
98
0
0
US
I have a website that I'm working on. People can subscribe to a mailing list when they enter their email address then click the submit button. Unfortunately, when they click the submit button an error 500 screen comes up. I have a mailing.txt form that is supposed to be utilized during this process. I am new to cgi so I don't even know if this is the way the mailing.txt is supposed to look. Error 500 and no email sent. Please help??

From:
To: username@soandso.com
Subject: Add Me To Your Mailing List!

Email Address: [email]
 
We'll need more than that to go on, can you post the code.

Also if you look at your webserver's error logs, you'll find a more meaningful message.

First off a script nomrally ends in .pl, or .cgi

Also please advise your webserver, and operating system

Regards
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I'm not exactly sure but I "think" this is the script. It's the only script I can find that refers to mail. I do not have access to the server itself as this is a leased hosting.

Please advise further??

sub SendMail{
my($to,$from,$subject,$message,$mailserver,$cc,$bcc) = @_;

@allto = split(",",$to);
@allcc = split(",",$cc);
@allbcc = split(",",$bcc);

use Net::SMTP;
(!$to)&&(return 0);
(!$subject)&&(!$message)&&(return 0);

@s = split("\n",$subject);

eval {

my $smtp = Net::SMTP->new($mailserver, Debug=>0);

$smtp->mail( $from );
$smtp->to(@allto);
$smtp->data();

$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $s[0]\n");
for $i (1..$#s){
$smtp->datasend("$s[$i]\n");
}
$smtp->datasend("\n");

$smtp->datasend("$message");
$smtp->dataend();
$smtp->quit;

if(@allcc){
my $smtp = Net::SMTP->new($mailserver, Debug=>0);
$smtp->mail( $from );
$smtp->to(@allcc);
$smtp->data();

$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("CC: $cc\n");
$smtp->datasend("Subject: $s[0]\n");
for $i (1..$#s){
$smtp->datasend("$s[$i]\n");
}
$smtp->datasend("\n");

$smtp->datasend("$message");
$smtp->dataend();
$smtp->quit;
}

if(@allbcc){
my $smtp = Net::SMTP->new($mailserver, Debug=>0);
$smtp->mail( $from );
$smtp->to(@allbcc);
$smtp->data();

$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $s[0]\n");
for $i (1..$#s){
$smtp->datasend("$s[$i]\n");
}
$smtp->datasend("\n");

$smtp->datasend("$message");
$smtp->dataend();
$smtp->quit;
}


};
if ($@) {
print "Error occured while trying to send a mail to $mailserver<br>";
return 0;
}


return 1;
}
1;
 
That appears to be a 'required file', if you look at the html form, the form action should point to the requisite script
<form method-post action=/cgi-bin/script.pl>

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks PaulTEG. It does look like it points to the right script and I check the directory structure to make sure the mailing.txt was in the right place???

FORM METHOD="POST" ACTION=" target="_self">
<INPUT TYPE="hidden" NAME="success" VALUE="<table cellpadding="0" cellspacing="0" border="0">
<tr><td colspan="2"><img src="images/sign_up.gif"></td></tr>
<tr>
<td><input name="email" type="text" id="email" size="17"></td><td><input name="Submit" type="image" src="images/submit.gif" value="Submit"></td>
</tr>
<tr><td colspan="2"><img src="images/enter_email.gif"></td></tr>
</table>
</form>
 
what did you find in the error logs? Also, post the contents of mailing.txt, and I believe it should be renamed to mailing.pl, both on the filesystem, and in the HTML that calls it, namely the action part of your script

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
FORM METHOD="POST" ACTION=" target="_self">

method =POST means that the form information is sent in the POST parameter for the form as oppesed to the QUERY_LENGTH which would be the GET method
ACTION= ... means direct this form to the script on the given server.

Mailing.txt doens't appear to have any code associated with it, just a parameter file so the actual script which should be using it, does a substiutution and changes the email addresses where is, and then sends.

There's a piece of the puzzle missing;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Okay then I guess I need to suck it up look stupid. Do you happen to know which piece of the puzzle is missing. I never claimed to know anything about cgi.
 
Where did you get the instructions ... and no, not stupid, you're working with what you got, ...

Usually there's a script (.pl, or .cgi) which would take the information from the form and do the substitution.

Any .pl files, or .cgi's in your cgi-bin directory ...?

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Okay, I don't have any instructions and I don't know cgi. I was given this site and asked to find out why this portion of it doesn't work.

I do have two files in my cgi-bin directory: randhtml.cgi and entropybanner.cgi. I cannot look at either one of these files in notepad but can look at all of the others.
 
Have you more than one cgi-bin folder perhaps?

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
You are correct in saying I may have more that one cgi-bin folder. I have another cgi-bin directory with 4 files in it: cgiecho, cgiemail, entropybanner.cgi, and randhtml.cgi. I can see what is in the files cgiecho or cgiemail. When I open them they are just symbols.

Thanks for "hanging in" the with me.
 
Code:
#!/usr/bin/perl
use CGI;
$q=new CGI;
print $q->start_html();
print "hello world from (insert path to cgi-bin)";
print $q->end_html;

Create a file, insert the contents above, change the paths to cgi-bin, so you know which one is live. Don't forget to set the permissions, and ownerships if needs be.

Once we have the right cgi-bin directory, we'll make progress
to access the script above. Or if it's being run on a local machine

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks PaulTEG!! I have not gotten any of this to work so far. The site is up and running but still no email sent. What next??

I tried the script that you sent but couldn't access that either. Had another tech look at it and the same thing.

Thanks
L
 
Can you give me temporary access to the server? If you're agreeable, I'll set up a temp email address, and delete that when concluded.
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Hi,

I have a cgi script as well...

<code>
#!/usr/local/bin/perl

use CGI;

#----------
# Validate: Email

sub check_email
{
local($email, $optional) = @_;

if ( (length($email) == 0) && ($optional == 1) ) {
return 1;
}
elsif ( $email !~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ && $email =~ /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i ) {
return 1;
}
else {
return 0;
}
}

$query = new CGI;
if (defined $ENV{'HTTP_X_FORWARDED_FOR'}) {
$ClientIP = $ENV{'HTTP_X_FORWARDED_FOR'};
} else {
$ClientIP = $ENV{'REMOTE_ADDR'};
}

$mailProg = '/usr/sbin/sendmail -t';

$subject = $query->param("subject");
$Day = $query->param("Day");
$Month = $query->param("Month");
$Year = $query->param("Year");
$Hour1 = $query->param("Hour1");
$Minute1 = $query->param("Minute1");
$Hour2 = $query->param("Hour2");
$Minute2 = $query->param("Minute2");
$Hour3 = $query->param("Hour3");
$Minute3 = $query->param("Minute3");
$venue_address1 = $query->param("venue_address1");
$venue_address2 = $query->param("venue_address2");
$venue_address3 = $query->param("venue_address3");
$venue_address4 = $query->param("venue_address4");
$venue_postcode = $query->param("venue_postcode");
$occasion = $query->param("occasion");
$contact_name = $query->param("contact_name");
$contact_address1 = $query->param("contact_address1");
$contact_address2 = $query->param("contact_address2");
$contact_address3 = $query->param("contact_address3");
$contact_address4 = $query->param("contact_address4");
$contact_phone = $query->param("contact_phone");
$contact_email = $query->param("contact_email");
$textarea = $query->param("textarea");
$Submit = $query->param("Submit");
$Reset = $query->param("Reset");


# Field Validations

$validationFailed = 0;

if ( (! check_email($contact_email, 0))) {
$validationFailed = 1;
}

# Redirect user to the error page

if ($validationFailed == 1) {

print "Location: error.html";
exit;

}

# Email to Form Owner

$emailTo = '"Dan" <dan@isobel-official.net>';

$emailFrom = $contact_email;
$emailFrom =~ s/[\x00-\x1F]//g;

$emailSubject = "Blah";
$emailSubject =~ s/[\x00-\x1F]//g;

open(MAIL,"|$mailProg");
print MAIL "To: $emailTo\n";
print MAIL "From: $emailFrom\n";
print MAIL "Subject: $emailSubject\n";
print MAIL "Reply-To: $emailFrom\n";
print MAIL "Return-Path: $emailFrom\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "X-Sender: $emailFrom\n";
print MAIL "Content-Type: text/plain; charset=\"ISO-8859-1\"\n";
print MAIL "Content-Transfer-Encoding: 8bit\n";
print MAIL "\n";
print MAIL "subject: $subject\n"
. "Day: $Day\n"
. "Month: $Month\n"
. "Year: $Year\n"
. "Hour1: $Hour1\n"
. "Minute1: $Minute1\n"
. "Hour2: $Hour2\n"
. "Minute2: $Minute2\n"
. "Hour3: $Hour3\n"
. "Minute3: $Minute3\n"
. "venue_address1: $venue_address1\n"
. "venue_address2: $venue_address2\n"
. "venue_address3: $venue_address3\n"
. "venue_address4: $venue_address4\n"
. "venue_postcode: $venue_postcode\n"
. "occasion: $occasion\n"
. "contact_name: $contact_name\n"
. "contact_address1: $contact_address1\n"
. "contact_address2: $contact_address2\n"
. "contact_address3: $contact_address3\n"
. "contact_address4: $contact_address4\n"
. "contact_phone: $contact_phone\n"
. "contact_email: $contact_email\n"
. "textarea: $textarea\n"
. "Submit: $Submit\n"
. "Reset: $Reset\n"
. "\n"
. "";
print MAIL "\n";
close(MAIL);

# Redirect user to success page

print "Location: success.html";
exit;

# End of Perl script
</code>

I keep getting a 500 Internal Server Error,

What am I doing wrong? The cgi file is in /cgi-bin/ and the form links to it
<form action="/cgi-bin/form.cgi" method="POST">
but I think it may have something to do with the 'PERL PATH' or 'SENDMAIL PATH'...

HELP ME, please...
 
Hi

First of all, for your own question start a new thread.

If you use the CGI module, use it to set the response header too :
Code:
print $query->redirect("success.html");
If you still want to output it "by hand", at least close the HTTP header :
Code:
print "Location: success.html[red]\r\n\r\n[/red]";

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top