Forum Moderators: coopster & phranque

Message Too Old, No Replies

Formatting email from perl/cgi formmail script

Formatting email from perl/cgi formmail script

         

MMEric

6:00 pm on Feb 1, 2006 (gmt 0)

10+ Year Member



Hi. I need help fixing my formatting for the email that results from this perl/cgi script. Currently when I process requests through this form the resulting emails look like what you see below instead of being fully integrated into the message:

Help Desk Form submission from

(address1@private.com) on Wednesday, February 01, 2006 at 09:23:42

Organization:

Phone: () - Ext:

---------------------------------------------------------------------------

Message:

---------------------------------------------------------------------------

firstname: eric

organization: org1

lastname: primmer

verifyemail: eprimmer@mindandmedia.com

phone: 222

phone2: 222

phone3: 2222

message: this email should go to agency1 email address

privacy: checkbox

Submit: Submit

---------------------------------------------------------------------------


#!/usr/bin/perl -wT
#
# NMS FormMail Version 3.14c1
#
.
.
.

# PROGRAM INFORMATION
# -------------------
# FormMail.pl Version 3.14c1
.
.
.

BEGIN
{
$DEBUGGING = 1;
$emulate_matts_code= 0;
$secure = 1;
$allow_empty_ref = 1;
$max_recipients = 2;
$mailprog = '/usr/lib/sendmail -oi -t';
$postmaster = 'address@agency.mil';
@referers = qw(sub.agency.mil localhost);
@allow_mail_to = ();
@recipients = ();
%recipient_alias = (
'Feedback' => 'helpdesk@agency.mil',
'Initiative' => 'helpdesk@agency.mil',
'Training' => 'helpdesk@agency.mil',
'Other' => 'helpdesk@agency.mil',
'Accountability' => 'address2@agency2.mil',
'Support' => 'Websupport@private.com',
);
@valid_ENV = qw(REMOTE_HOST REMOTE_ADDR REMOTE_USER HTTP_USER_AGENT);
$locale = '';
$charset = 'iso-8859-1';
$date_fmt = '%A, %B %d, %Y at %H:%M:%S';
$style = '/css/nms.css';
$no_content = 0;
$double_spacing = 1;
$wrap_text = 0;
$wrap_style = 1;
$address_style = 0;
$send_confirmation_mail = 0;
$confirmation_text = <<'END_OF_CONFIRMATION';
.
.
.

sub send_main_email_body_header {
my ($self, $date) = @_;

my $dashes = '-' x 75;
$dashes .= "\n\n" if $self->{CFG}{double_spacing};

$self->mailer->print(<<END);

Agency Help Desk Form submission from
$self->{FormConfig}{firstname} $self->{FormConfig}{lastname}($self->{FormConfig}{email}) on $date
$self->{FormConfig}{subject} $self->{FormConfig}{recipients}
Organization: $self->{FormConfig}{organization}
Phone: ($self->{FormConfig}{phone}) $self->{FormConfig}{phone2} - $self->{FormConfig}{phone3} Ext: $self->{FormConfig}{phone4}
$dashes
Message: $self->{FormConfig}{message}

$dashes
END
}

.
.
.

Please help!

milanmk

12:12 pm on Feb 3, 2006 (gmt 0)

10+ Year Member



instead of being fully integrated into the message

Explain.

MMEric

2:09 pm on Feb 3, 2006 (gmt 0)

10+ Year Member



The problem I was having was that the send_main_email_body_header section wasn't coded right. I was trying to use pass my form values into the email header in this section, but they were showing up blank in my email. The reason, apparently, was that I was using a format like this: $self->{FormConfig}{"myformvariablename"}. When I needed to use a format like this for my own defined form fields such as "organization": $self->{Form}{"myformvariablename"}.

I was also confused that I was seeing my form values appear later in the email. This is apparently happening later in the formmail code. I'd actually still like advice on getting rid of the standard section of the formmail email that prints each of the form variables. I don't need this section now that I have included these values in body copy of my email header.

Anyone no how to get rid of this?

sub send_main_email_body_header {
my ($self, $date) = @_;

my $dashes = '-' x 75;
$dashes .= "\n\n" if $self->{CFG}{double_spacing};

$self->mailer->print(<<END);

Agency Help Desk Form submission from
$self->{FormConfig}{firstname} $self->{FormConfig}{lastname}($self->{FormConfig}{email}) on $date
$self->{FormConfig}{subject} $self->{FormConfig}{recipients}
Organization: $self->{FormConfig}{organization}
Phone: ($self->{FormConfig}{phone}) $self->{FormConfig}{phone2} - $self->{FormConfig}{phone3} Ext: $self->{FormConfig}{phone4}
$dashes
Message: $self->{FormConfig}{message}

$dashes
END
}

milanmk

7:35 pm on Feb 3, 2006 (gmt 0)

10+ Year Member



I really dont understand what you are trying to say :(

Well, here is the formmail code which i use personally for getting a nice formated table content.

If you are looking for formatting email then this is it.

#!/usr/bin/perl

$recipient = 'me@domain.com';

$redirect = 'http://domain.com/thankyou.htm';

$mailprog = '/usr/lib/sendmail -t';

&parse_form;

&send_mail;

&redirect;

sub parse_form {
%Config = ('realname','', 'email','', 'subject','', 'comment','');

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}

foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/\0//d;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/\0//d;

if (defined($Config{$name})) {
$Config{$name} = $value;
}
else {
if ($Form{$name} ne '') {
$Form{$name} = "$Form{$name}, $value";
}
else {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
}

}

sub send_mail {

open(MAIL,"¦ $mailprog");

print MAIL "To: $recipient\n";
print MAIL "From: $Config{'email'} ($Config{'realname'})\n";
print MAIL "Content-Type: text/html\n";
print MAIL "Subject: $Config{'subject'}\n";

print MAIL <<_MAIL_;

<table border="0">
<tr> <td>Name</td> <td>: $Config{'realname'}</td> </tr>
<tr> <td>Email</td> <td>: $Config{'email'}</td> </tr>
<tr> <td valign="top">Suggestion</td><td>: $Config{'comment'} <br><br></td> </tr>
</table>

_MAIL_

close (MAIL);
}

sub redirect {

print "Location: $redirect\n\n";

}

MMEric

8:20 pm on Feb 3, 2006 (gmt 0)

10+ Year Member



I guess I wasn't very clear. Either way, I think I worked it out. Thanks