#!/usr/local/bin/perl -w
use CGI;
use strict;
my $q = new CGI;
my $emailoutput = '/tmp/email.data';
use MIME::Lite;
use Text::Correct qw{ wrap };
my $tp = $q->param('textPLAIN')."\n";
my $th = $q->param('textHTML')."\n";
# Section just for debugging (output to files and browser)
print $q->header;
print "plain pre:
\n $tp
\n";
print "html pre:
\n $th
\n";
open O,">/tmp/o1";
print O $tp;
close O;
open O,">/tmp/o2";
print O $th;
close O;
my $wtp = wrap(' ','',$tp);
my $wth = wrap(' ','',$th);
# More debugging (output to files and browser)
open O,">/tmp/o3";
print O "$wtp";
close O;
open O,">/tmp/o4";
print O "$wth";
close O;
print "plain post:
\n $wtp
\n";
print "html post:
\n $wth
\n";
# Start the message
my $msg = MIME::Lite->new(
From =>$q->param('emailFrom'),
To =>$q->param('emailTo'),
Subject =>$q->param('emailSubject'),
Type =>'multipart/alternative',
);
$msg->attach(
Type =>'TEXT',
Data =>"$wtp\n",
);
$msg->attach(
Type =>'text/html',
Data =>"$wth\n",
Encoding =>'7bit',
);
# Add character set (required header)
$msg->attr("content-type.charset" => "US-ASCII");
# Remove headers (another requirement)
$msg->scrub(['content-transfer-encoding','content-disposition']);
# Final output of script to file (yet another requirement)
open(OUTFILE,">$emailoutput") or die "Unable to open $emailoutput: $!";
$msg->print(\*OUTFILE);
close OUTFILE;