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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI PHP problem

Status
Not open for further replies.

jenodorf

Technical User
Jan 11, 2005
36
HI

Is the same sendmail used in a PHP script the same as in a CGI script?

Problem is I've created a mail form using both PHP and a version using CGI

The PHP version works but the CGI gives me the generic server error. The sendmail path is correct and the ISP is saying it's a script error although I've used two different mail scripts

If anyone has any ideas I'd be grateful

cheers

Ian
 
Hi sorry the script is as below

#!/usr/bin/perl
# ----------------------------------------------------
# -----
# ----- Forms To Go v2.5.9 by Bebosoft, Inc.
# -----
# ----- # -----
# ----------------------------------------------------


#----------
# Validate: String

sub check_string
{
local($value, $low, $high, $mode, $optional) = @_;

if ( (length($value) == 0) && ($optional == 1) ) {
return 1;
}
elsif ((length($value) >= $low) && ($mode == 1)) {
return 1;
}
elsif ((length($value) <= $high) && ($mode == 2)) {
return 1;
}
elsif ((length($value) >= $low) && (length($value) <= $high) && ($mode == 3)) {
return 1;
}
else {
return 0;
}
}
#----------
# Validate: Email

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

if ( (length($email) == 0) && ($optional == 1) ) {
return 1;
}
elsif ( $email !~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ && $email =~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/ ) {
return 1;
}
else {
return 0;
}
}

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

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;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}

$name = $FORM{'name'};
$email = $FORM{'email'};
$Submit = $FORM{'Submit'};

# Field Validations

$validationFailed = 0;

if ( (! check_string($name, 1, 0, 1, 0))) {
$validationFailed = 1;
}

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

# Embed error page and dump it to the browser

if ($validationFailed == 1) {

$fileErrorPage = 'error.html';

if (!(-e $fileErrorPage)) {
print "Content-type: text/html\n\n";
print 'The error page: <b>error.html</b> cannot be found on the server.';
exit;
}

open(HANDLE, $fileErrorPage);
@errorPage = <HANDLE>;
close(HANDLE);

foreach $pageLine (@errorPage) {
$errorPage .= $pageLine;
}

$errorPage =~ s/<!--VALIDATIONERROR-->/$errorList/;

$errorPage =~ s/<!--FIELDVALUE:name-->/$name/;
$errorPage =~ s/<!--FIELDVALUE:email-->/$email/;
$errorPage =~ s/<!--FIELDVALUE:Submit-->/$Submit/;


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

}


# Email to Form Owner

$emailTo = '"ian" <ian@thestoragecompany.co.uk>';

$emailFrom = $email;

$emailSubject = "trial";

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 "X-Sender: $emailFrom\n";
print MAIL "Content-Type: text/plain; charset:\"ISO-8859-1\"\n";
print MAIL "Content-Transfer-Encoding: quoted-printable\n";
print MAIL "\n";
print MAIL "name: $name\n"
. "email: $email\n"
. "Submit: $Submit\n"
. "\n"
. "this is an email from a client to the company it is the tenth trial using php\n"
. "\n"
. "";
print MAIL "\n";
close(MAIL);

# Confirmation Email to User

$confEmailTo = $email;

$confEmailFrom = 'ian@thestoragecompany.co.uk';

$confEmailSubject = "test";

open(MAIL,"|$mailProg");
print MAIL "To: $confEmailTo\n";
print MAIL "From: $confEmailFrom\n";
print MAIL "Subject: $confEmailSubject\n";
print MAIL "Content-Type: text/plain; charset:\"ISO-8859-1\"\n";
print MAIL "Content-Transfer-Encoding: quoted-printable\n";
print MAIL "\n";
print MAIL "we have recieved your email and will respond in due course the email inout will be zen15006\@zen.co.uk\n"
. "";
close(MAIL);

# Embed success page and dump it to the browser

$fileSuccessPage = 'success.html';

if (!(-e $fileSuccessPage)) {
print "Content-type: text/html\n\n";
print 'The success page: <b>success.html</b> cannot be found on the server.';
exit;
}

open(HANDLE, $fileSuccessPage);
@successPage = <HANDLE>;
close(HANDLE);

foreach $pageLine (@successPage) {
$successPage .= $pageLine;
}

$successPage =~ s/<!--FIELDVALUE:name-->/$name/;
$successPage =~ s/<!--FIELDVALUE:email-->/$email/;
$successPage =~ s/<!--FIELDVALUE:Submit-->/$Submit/;

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

# End of Perl script


thanks

Ian
 
Add a 'die' and run the script. Also add taint checking for security reasons.
Code:
my $mailProg = "/usr/sbin/sendmail -oi -oeq -t";

open(MAIL,"|$mailProg") [b]or die "Error: $!"[/b];

 
Ok

I admit it languages were never my forte.

I'm sure the code you've given me makes perfect sense

"my $mailProg = "/usr/sbin/sendmail -oi -oeq -t";

open(MAIL,"|$mailProg") or die "Error: $!";"

Could you possibly take the time to supply an idiots guide

thanks

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top