A
andrey the giant
Vim doesn't give me any red marks and the code looks right, but I get
the following errors:
syntax error at contact.pl line 50, near ")
{"
syntax error at contact.pl line 64, near "}"
contact.pl had compilation errors.
The code is a cgi email script. All sensitive data has been
genericized.
The code is:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use Email::MIME::Creator;
use Email::Sender::Simple qw(sendmail);
use Try::Tiny;
our $cgi = CGI->new;
our $name = $cgi->param('name');
our $addr = $cgi->param('email');
our $subject = $cgi->param('subj');
our $xdest = $cgi->param('dest');
our $message = $cgi->param('body');
our $urgent = $cgi->param('urgent');
if ( !defined($subject) || !length($subject) ) { $subject = ""; }
if ( !defined($urgent) || !length($urgent) ) { $urgent = "no"; }
my $defineds = 0;
$defineds |= 1 if ( defined($name) && length($name) );
$defineds |= 2 if ( defined($addr) && length($addr) );
$defineds |= 4
if ( defined($xdest) && length($xdest) && ( $xdest =~ /[aucm]/ ) );
$defineds |= 8 if ( defined($message) && length($message) );
our $complete = ( $defineds == 15 );
our $ret = 0;
our $err = "";
if ($complete) {
our $dest;
our $SMS = '(e-mail address removed)';
if ( $xdest =~ /a/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /u/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /c/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /m/ ) { $dest = '@example.com'; }
our $email = Email::MIME->create(
header => [
From => $name . ' <' . $addr . '>',
To => $dest,
Subject => $subject,
'X-Source' => 'webform',
],
body => $message,
);
try {
sendmail( $email, { from => '(e-mail address removed)' } );
$ret = 1;
}
catch { $ret = 2; $err = "$_"; }
if ( ( $urgent =~ /yes/ ) && ( $ret != 2 ) )
{ #error here
$email = Email::MIME->create(
header => [
From => '(e-mail address removed)',
To => $SMS,
],
body => "Urgent message in $dest.\n",
);
try {
sendmail( $email, { from => '(e-mail address removed)' } );
$ret = 3;
}
catch { $ret = 4; $err = "$_"; };
}
} #and here
print $cgi->header();
if ( $ret == 0 ) {
print $cgi->start_html('Message not sent'),
"Not all required fields were filled", $cgi->end_html();
}
elsif ( $ret == 1 ) {
print $cgi->start_html('Message sent'), "Message successfully
sent",
$cgi->end_html();
}
elsif ( $ret == 2 ) {
print $cgi->start_html('Error sending mail'), "Sendmail: $err",
$cgi->end_html();
}
elsif ( $ret == 3 ) {
print $cgi->start_html('Message sent'),
"Message successfully sent, mobile notifed", $cgi->end_html();
}
elsif ( $ret == 4 ) {
print $cgi->start_html('Error sending mail'),
"Message successfully sent, but mobile could not be notified:
$err",
$cgi->end_html();
}
the following errors:
syntax error at contact.pl line 50, near ")
{"
syntax error at contact.pl line 64, near "}"
contact.pl had compilation errors.
The code is a cgi email script. All sensitive data has been
genericized.
The code is:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use Email::MIME::Creator;
use Email::Sender::Simple qw(sendmail);
use Try::Tiny;
our $cgi = CGI->new;
our $name = $cgi->param('name');
our $addr = $cgi->param('email');
our $subject = $cgi->param('subj');
our $xdest = $cgi->param('dest');
our $message = $cgi->param('body');
our $urgent = $cgi->param('urgent');
if ( !defined($subject) || !length($subject) ) { $subject = ""; }
if ( !defined($urgent) || !length($urgent) ) { $urgent = "no"; }
my $defineds = 0;
$defineds |= 1 if ( defined($name) && length($name) );
$defineds |= 2 if ( defined($addr) && length($addr) );
$defineds |= 4
if ( defined($xdest) && length($xdest) && ( $xdest =~ /[aucm]/ ) );
$defineds |= 8 if ( defined($message) && length($message) );
our $complete = ( $defineds == 15 );
our $ret = 0;
our $err = "";
if ($complete) {
our $dest;
our $SMS = '(e-mail address removed)';
if ( $xdest =~ /a/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /u/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /c/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /m/ ) { $dest = '@example.com'; }
our $email = Email::MIME->create(
header => [
From => $name . ' <' . $addr . '>',
To => $dest,
Subject => $subject,
'X-Source' => 'webform',
],
body => $message,
);
try {
sendmail( $email, { from => '(e-mail address removed)' } );
$ret = 1;
}
catch { $ret = 2; $err = "$_"; }
if ( ( $urgent =~ /yes/ ) && ( $ret != 2 ) )
{ #error here
$email = Email::MIME->create(
header => [
From => '(e-mail address removed)',
To => $SMS,
],
body => "Urgent message in $dest.\n",
);
try {
sendmail( $email, { from => '(e-mail address removed)' } );
$ret = 3;
}
catch { $ret = 4; $err = "$_"; };
}
} #and here
print $cgi->header();
if ( $ret == 0 ) {
print $cgi->start_html('Message not sent'),
"Not all required fields were filled", $cgi->end_html();
}
elsif ( $ret == 1 ) {
print $cgi->start_html('Message sent'), "Message successfully
sent",
$cgi->end_html();
}
elsif ( $ret == 2 ) {
print $cgi->start_html('Error sending mail'), "Sendmail: $err",
$cgi->end_html();
}
elsif ( $ret == 3 ) {
print $cgi->start_html('Message sent'),
"Message successfully sent, mobile notifed", $cgi->end_html();
}
elsif ( $ret == 4 ) {
print $cgi->start_html('Error sending mail'),
"Message successfully sent, but mobile could not be notified:
$err",
$cgi->end_html();
}