PDA

View Full Version : Formmail variant... Cleaning up the output email


a4udi
02-22-2005, 04:20 PM
I'm trying to modify an alternate version of formmail below.

currently it spits out results as follows:

"S1_First_Name" ============> "sdfsdf"
"S1_Last_Name" ============> "sdfsd"
"S1_Address" ============> "sdfsd"


Is there any way to clean this up or at least to Bold the results?

ex.

"S1_First_Name" ==========> "sdfsdf"
"S1_Last_Name" ==========> "sdfsd"
"S1_Address" ============> "sdfsd"


$message = $email_format;

# make all necessary variable exchanges
while($message =~ m/<\$([0-9]|[a-z]|[A-Z]|_|\-|!>)+>/gc) {
my $var = $&;

$var =~ s/^(<\$)|>$//g;

my $val = '['.$var.' - undefined]';

# firstly, is it an internal variable?
if($var eq 'senttime') {
$val = &senttime;
} elsif ($var eq 'all_vars') {
$val = '';
my $key;
foreach $key (@params) { $val .= "\"$key\" ============> \"".param($key)."\"\n"; }
} else {
# the variable is POST or GET, swap it
if(defined param($var)) {
$val = param($var);
} else {
# hrm, is it an environment variable?
if(defined $ENV{$var}) {
# yup, make the change
$val = $ENV{$var};
} else {
# is it a cookie?
if(defined cookie($var)) {
# yay
$val = cookie($var);
}
}
}
}

$message =~ s/<\$$var>/$val/g;
}

$message =~ s/\n/\r\n/g;

mlseim
02-22-2005, 05:38 PM
I don't understand what you mean by "cleaning it up".

This is the line that is displaying all of the variables
that are appearing in the form:

foreach $key (@params) { $val .= "\"$key\" ============> \"".param($key)."\"\n"; }

You could change it to something like:

foreach $key (@params) { $val .= "$key: "."param($key)\n"; }

S1_First_Name: sdfsdf
S1_Last_Name: sdfsd
S1_Address: sdfsd

a4udi
02-22-2005, 05:53 PM
I meant just a more readable format... maybe aligned or something.

I know that's the display line, I'm just not sure what I can do with it. I mean is there a command to display the text bolded in perl, or would i just wrap it in <b></b> or something? :confused:

mlseim
02-22-2005, 06:28 PM
... I just realized it's getting emailed not displayed, so my
idea of using tables is out.

You can try HTML with your email, it may or may not render it.

<b>bold</b>

a4udi
02-22-2005, 07:20 PM
I tried wrapping it like this

foreach $key (@params) { $val .= "\"$key\" ============> <b>\"".param($key)."\"</b>\n"; }


That obviously didn't work out... just printed the <b> tags in the email. So is there a "bold" or "color" command in perl that I can add to the line above?

mlseim
02-22-2005, 07:39 PM
Other than setting your email program to accept HTML,
I can't think of any way to do anything except plain text.

Give us a link to your form that you are having emailed to you.

Maybe we can come up with a nicer way to email you the results.

a4udi
02-23-2005, 05:32 PM
I actually managed to do the email as html and modify the code so that it spit out the variables in a colour coded table, so it looks a thousand times better now! Thanks for the ideas! :thumbsup: