Jump to content

Recommended Posts

Posted

I've got a CGI file I tweaked that will take the contents of an HTML form, and send it to my email account when the user clicks "Send" button.

 

it operates on the "sendmail" thingy:

 

$sendmail_loc = "/usr/sbin/sendmail";

 

(that was my old server's address to the sendmail), so do our servers have this sendmail? or is there another way I'm going to have to do this?

Posted

sweet, thanks. yep exactly what i needed.

but of course, I'm not done fixing the problems, apparently...

 

to implement the CGI file, i uploaded it into the CGI bin, and played around with setting the permissions (attributes, properties, whatever) 777, 755, etc. The browser was recognizing the file (500 error, not 404 can't-find-it error), but said the page could not be displayed. and no email was sent.

 

it's been a while since i've done this stuff, if anybody out there would like to attempt to help me I'd GREATLY appreciate it.

 

 

here's the source just incase you want a look:

 

#!/usr/bin/perl

 

$sendmail_loc = "/usr/sbin/sendmail";

 

$sendername = "Robby Kraft";

$fromemail = "robby@pinesofrome.net";

$mail_subject = "PINES OF ROME email list";

$toemail = "robby@pinesofrome.net";

 

if ($ENV{'QUERY_STRING'} ne ""){$temp = $ENV{'QUERY_STRING'};}

else{read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});}

@pairs=split(/&/,$temp);

foreach $item(@pairs)

{

($key,$content)=split (/=/,$item,2);

$content=~tr/+/ /;

$content=~ s/%(..)/pack("c",hex($1))/ge;

$fields{$key}=$content;

$crit = chr(13);

if (($key ne "button") and ($key ne "fn"))

{

if ((length($content) > 40) or ($content =~ /$crit/) or ($content =~ /\n/))

{

$email = $email . "\n$key:\n";

$email = $email . "===============\n";

$email = $email . "$content\n\n";

}

else

{

$email = $email . "$key: $content\n";

}

}

}

 

#### SEND MAIL TO FROM CONTACT FORM

&send_email ($sendmail_loc, $sendername, $fromemail, $toemail, $mail_subject, $email);

 

 

print "Content-type: text/html\n\n";

print "<BODY bgcolor="#000000">";

print "<br><p align=\"center\"><font face=\"arial\" color=\"0088AF\" size=\"6\"><b><u>Thank you</b></u><font size=\"3\" color=\"A0A0A0\"><br><br>";

print "You have been added";

print "<br><br><br><br><br><br><br><font size=\"2\">Close this window to return to Pines of Rome";

exit;

 

 

sub send_email

{

 

my($sendmail_loc, $sendername, $fromemail, $toemail, $mail_subject, $email_message) = @_;

 

### check for attacks

 

$toemail =~ s/\;//g;

$toemail =~ s/^\s+//g;

$toemail =~ s/\s+$//g;

if ($toemail =~ /^\S+\@\S+$/)

{

 

open (SENDMAIL, "| $sendmail_loc $toemail");

print SENDMAIL <<End_of_Mail;

From: $sendername

To: $toemail

Reply-To: $fromemail

Subject: $mail_subject

Sender: $fromemail

 

$email_message

 

End_of_Mail

 

}

 

}

Posted

I can't help with that script,

but I do know that the php script

Dodosmail is popular and works very well and can hide your e-mail from spammers.

 

 

Maybe someone will be along soon to help with your script.

Posted

Did you upload your Perl script in ASCII mode. That is what usually causes a 500 error. Or a missing ";"

 

For the mail program I use. /usr/sbin/sendmail -t

 

Here is how I normally send mail through Perl.

 

 

 

>$mailprog = '/usr/sbin/sendmail -t';

open (MAIL, "|$mailprog");
print MAIL "Reply-to: $E_mail\n";
print MAIL "From: $E_mail\n";
print MAIL "To: $recip\n";
print MAIL "Subject: Sirius Sales Request\n";
print MAIL "\n\n";
print MAIL "";

more print statements for all variables, etc...

print MAIL "\n\n";
close (MAIL);

Posted

i hate persuing this, 'cause I know the problem is something incredibly small, just because I don't know CGI programming too well.

 

thank you very much bruce for the code, here's what i made:

 

email.cgi

>#!/usr/bin/perl

$mailprog = "/usr/sbin/sendmail -t";

open (MAIL, "|$mailprog");
print MAIL "Reply-to: robby@pinesofrome.net\n";
print MAIL "From: robby@pinesofrome.net\n";
print MAIL "To: robby@pinesofrome.net\n";
print MAIL "Subject: PINES OF ROME email list\n";
print MAIL "\n\n";
print MAIL "Add these following names to the list\n\n";

print MAIL "\n\n";
close (MAIL);

 

I'm making sure I upload it in ASCII every time, and make sure the permissions are set to 755.

 

I test it with this:

 

form.html

><HTML>
<HEAD>
<TITLE>Form Tester</TITLE>
</HEAD>

<BODY bgcolor="#000000" link="#0099CC" vlink="#006699" alink="#0099CC">
<font face="arial" color="#FFFFFF">

<form action="http://www.pinesofrome.net/cgi-bin/email.cgi" method="POST">
Email Address: <input type="text" name="contactemail" size=20 value="" maxlength=50>
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>

</BODY>
</HTML>

 

I really don't see a problem with the code. Is there some settings I need to set for my CGI-bin or something?

 

thank you all

  • 2 years later...
Posted

Has this change? I'm trying to send an email from a perl script using the following code:

 

 

...

 

$sendmail = "/usr/sbin/sendmail -t";

$reply_to = "Reply-to: webmaster\@yolol.net\n";

$subject = "Subject: Refurbish Report\n";

$to = " $current_user\n"; #Value adquired earlier in code

 

open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";

print SENDMAIL $reply_to;

print SENDMAIL $subject;

print SENDMAIL $to;

print SENDMAIL "Content-type: text/html\n\n";

print SENDMAIL $body; #Value adquired earlier in code

print SENDMAIL "\n\n";

 

close(SENDMAIL);

 

print "Mail sent";

 

...

 

I receive no errors but no message either :huh: any suggestions? :lol:

Posted

I use perl scripts and they are still working.

 

I don't use the "-t" flag on sendmail though.

 

And my open statement is like this:

 

>open (SENDMAIL, "|$sendmail -f$rcpf $recip");

 

The "$rcpf" is my sending email address, the "$recip" is the To address.

 

The "-f" flag from the man page:

 

>-fname	  Sets the name of the ``from'' person (i.e., the sender of the
		mail).  -f can only be used by ``trusted'' users (normally
		root, daemon, and network) or if the person you are trying to
		become is the same as the person you are.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...