marybailey
Programmer
I have a form to send email. In case you are interested, its at
There is a text area called personal message. When my client fills in this space with text that, say, has three bullet items, some indentations, spaces, <CR>s, all the formatting is lost.
Does anyone know if this is due to something in my html? Perhaps I have the textarea defined incorrectly?
Or is this happening in the perl script that sends the mail. The code for that follows. (Is there a better way to share this code?)
Thanks,
Mrs B
-------------PERL CODE FOLLOWS -------------------------
#!/usr/local/bin/perl
$mailprog = '/usr/lib/sendmail';
# Retrieve Date
&get_date;
# Parse Form Contents
&parse_form;
# Check Required Fields
&check_required;
# Send mail
&get_emails;
&do_work;
sub parse_form {
# Define the configuration associative array. #
%Config = ('jan','', 'feb','',
'mar','', 'apr','',
'may','', 'jun','',
'jul','', 'aug','',
'sep','', 'oct','',
'nov','', 'dec','',
'spec','', 'personalmsg','',
'emailsubject','');
# Determine the form's REQUEST_METHOD (GET or POST) and split the form #
# fields up into their name-value pairs. If the REQUEST_METHOD was #
# not GET or POST, send an error. #
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}
# For each name-value pair: #
foreach $pair (@pairs) {
# Split the pair up into individual variables. #
local($name, $value) = split(/=/, $pair);
# Decode the form encoding on the name and value variables. #
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# If they try to include server side includes, erase them, so they
# aren't a security risk if the html gets returned. Another
# security hole plugged up.
$value =~ s/<!--(.|\n)*-->//g;
# If the field name has been specified in the %Config array, it will #
# return a 1 for defined($Config{$name}}) and we should associate #
# this value with the appropriate configuration variable. If this #
# is not a configuration form field, put it into the associative #
# array %Form, appending the value with a ', ' if there is already a #
# value present. We also save the order of the form fields in the #
# @Field_Order array so we can use this order for the generic sort. #
if (defined($Config{$name})) {
$Config{$name} = $value;
}
else {
if ($Form{$name} && $value) {
$Form{$name} = "$Form{$name}, $value";
}
elsif ($value) {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
}
# The next six lines remove any extra spaces or new lines from the #
# configuration variables, which may have been caused if your editor #
# wraps lines after a certain length or if you used spaces between field #
# names or environment variables. #
$Config{'required'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'required'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'env_report'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'env_report'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'print_config'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'print_config'} =~ s/(\s+)?\n+(\s+)?//g;
# Split the configuration variables into individual field names. #
@Required = split(/,/,$Config{'required'});
@Env_Report = split(/,/,$Config{'env_report'});
# ACCESS CONTROL FIX: Only allow ENV variables in @valid_ENV in #
# @Env_Report for security reasons. #
foreach $env_item (@Env_Report) {
foreach $valid_item (@valid_ENV) {
if ( $env_item eq $valid_item ) { push(@temp_array, $env_item) }
}
}
@Env_Report = @temp_array;
}
sub check_required {
$jan = $Config{'jan'};
$feb = $Config{'feb'};
$mar = $Config{'mar'};
$apr = $Config{'apr'};
$may = $Config{'may'};
$jun = $Config{'jun'};
$jul = $Config{'jul'};
$aug = $Config{'aug'};
$sep = $Config{'sep'};
$oct = $Config{'oct'};
$nov = $Config{'nov'};
$dec = $Config{'dec'};
$spec = $Config{'spec'};
$personalmsg = $Config{'personalmsg'};
$prob_list = "";
$emailsubject = $Config{'emailsubject'};
sub do_work {
foreach $friend (@emailArr) {
open(MAIL,"|$mailprog -t"
print MAIL "To: $friend\n";
print MAIL "From: $friend\n";
print MAIL "Subject: $emailsubject\n";
print MAIL "Content-Type: text/html; charset=us-ascii\n\n";
print MAIL "<html>\n";
print MAIL "<head>\n";
print MAIL "</head>\n";
print MAIL "<style>\n";
print MAIL "</style>\n";
print MAIL "<body>\n";
print MAIL "<img src=\"http:\/\/ print MAIL "<P>";
print MAIL "$Config{'personalmsg'}<\/B><\/I>\n";
print MAIL "<P>\n";
print MAIL "</body>\n";
print MAIL "</html>\n";
close (MAIL);
}
}
There is a text area called personal message. When my client fills in this space with text that, say, has three bullet items, some indentations, spaces, <CR>s, all the formatting is lost.
Does anyone know if this is due to something in my html? Perhaps I have the textarea defined incorrectly?
Or is this happening in the perl script that sends the mail. The code for that follows. (Is there a better way to share this code?)
Thanks,
Mrs B
-------------PERL CODE FOLLOWS -------------------------
#!/usr/local/bin/perl
$mailprog = '/usr/lib/sendmail';
# Retrieve Date
&get_date;
# Parse Form Contents
&parse_form;
# Check Required Fields
&check_required;
# Send mail
&get_emails;
&do_work;
sub parse_form {
# Define the configuration associative array. #
%Config = ('jan','', 'feb','',
'mar','', 'apr','',
'may','', 'jun','',
'jul','', 'aug','',
'sep','', 'oct','',
'nov','', 'dec','',
'spec','', 'personalmsg','',
'emailsubject','');
# Determine the form's REQUEST_METHOD (GET or POST) and split the form #
# fields up into their name-value pairs. If the REQUEST_METHOD was #
# not GET or POST, send an error. #
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}
# For each name-value pair: #
foreach $pair (@pairs) {
# Split the pair up into individual variables. #
local($name, $value) = split(/=/, $pair);
# Decode the form encoding on the name and value variables. #
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# If they try to include server side includes, erase them, so they
# aren't a security risk if the html gets returned. Another
# security hole plugged up.
$value =~ s/<!--(.|\n)*-->//g;
# If the field name has been specified in the %Config array, it will #
# return a 1 for defined($Config{$name}}) and we should associate #
# this value with the appropriate configuration variable. If this #
# is not a configuration form field, put it into the associative #
# array %Form, appending the value with a ', ' if there is already a #
# value present. We also save the order of the form fields in the #
# @Field_Order array so we can use this order for the generic sort. #
if (defined($Config{$name})) {
$Config{$name} = $value;
}
else {
if ($Form{$name} && $value) {
$Form{$name} = "$Form{$name}, $value";
}
elsif ($value) {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
}
# The next six lines remove any extra spaces or new lines from the #
# configuration variables, which may have been caused if your editor #
# wraps lines after a certain length or if you used spaces between field #
# names or environment variables. #
$Config{'required'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'required'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'env_report'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'env_report'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'print_config'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'print_config'} =~ s/(\s+)?\n+(\s+)?//g;
# Split the configuration variables into individual field names. #
@Required = split(/,/,$Config{'required'});
@Env_Report = split(/,/,$Config{'env_report'});
# ACCESS CONTROL FIX: Only allow ENV variables in @valid_ENV in #
# @Env_Report for security reasons. #
foreach $env_item (@Env_Report) {
foreach $valid_item (@valid_ENV) {
if ( $env_item eq $valid_item ) { push(@temp_array, $env_item) }
}
}
@Env_Report = @temp_array;
}
sub check_required {
$jan = $Config{'jan'};
$feb = $Config{'feb'};
$mar = $Config{'mar'};
$apr = $Config{'apr'};
$may = $Config{'may'};
$jun = $Config{'jun'};
$jul = $Config{'jul'};
$aug = $Config{'aug'};
$sep = $Config{'sep'};
$oct = $Config{'oct'};
$nov = $Config{'nov'};
$dec = $Config{'dec'};
$spec = $Config{'spec'};
$personalmsg = $Config{'personalmsg'};
$prob_list = "";
$emailsubject = $Config{'emailsubject'};
sub do_work {
foreach $friend (@emailArr) {
open(MAIL,"|$mailprog -t"
print MAIL "To: $friend\n";
print MAIL "From: $friend\n";
print MAIL "Subject: $emailsubject\n";
print MAIL "Content-Type: text/html; charset=us-ascii\n\n";
print MAIL "<html>\n";
print MAIL "<head>\n";
print MAIL "</head>\n";
print MAIL "<style>\n";
print MAIL "</style>\n";
print MAIL "<body>\n";
print MAIL "<img src=\"http:\/\/ print MAIL "<P>";
print MAIL "$Config{'personalmsg'}<\/B><\/I>\n";
print MAIL "<P>\n";
print MAIL "</body>\n";
print MAIL "</html>\n";
close (MAIL);
}
}