Link to home
Start Free TrialLog in
Avatar of misterbrick
misterbrick

asked on

Sending plain text and html with MIME::Lite

I have an autoresponder script and am trying to set up an option in the script to send either plain text messages or html messages.
It currently will only send plain text with an attachment and the ability to personalize the messages.
The script uses MIME::Lite and sendmail. For the life of me I cannot figure out how to get this to work.
Below is the code for sending the messages.
Can any one help me?



sub sendmail{
     my($mon,$mday,$year) = ltime();
     my($to,$subject,$message,$path,$name,$idx,$username)=@_;
     my($email)=$to;
     $username=~/^\s*(\w{1,20})\s*(\w{0,20}).*$/;
     $secname=$2;$secname=~tr/A-Z/a-z/;$secname="\u$secname";
     $username=$1;$username=~tr/A-Z/a-z/;$username="\u$username";
     my($fromars,$namears,$unlink)=(getarlist("$path/$path.cfg"));
     $fromaddr="$namears<$fromars>";
     if ($unlink == 1) {$unlink="\r\n\r\n To unsubscribe:\r\n$scripturl?mode=r&a=$path&e=$to"}
     $to=~s/@/\@/;
     if ($secname ne ""){$secname=" ".$secname};
     $to="$username$secname <$to>";
     $name=~/.*\.(.*)/;
        my($real)="upfile$idx.$1";
     $path="$path/$real";
     my($current)="$mday/$mon/$year";
     $message=~s/\[FIRSTNAME\]/$username/gie;
     $message=~s/\[EMAIL\]/$email/gie;
     $message=~s/\[DATE\]/$current/gie;
     $message=~s/\[FULLNAME\]/$username.$secname/gie;
     $message.="\n\n$unlink\n\n";
     $subject=~s/\[FIRSTNAME\]/$username/gie;
     $subject=~s/\[EMAIL\]/$email/gie;
     $subject=~s/\[DATE\]/$current/gie;
     $subject=~s/\[FULLNAME\]/$username.$secname/gie;
     my($mime)=&mimeformat($name);
      my $msg = MIME::Lite->new
                 (Type =>'multipart/mixed',
                   From =>"$fromaddr",
               To =>"$to",
                Subject =>"$subject",
               Type => "TEXT",
               Data =>"$message");
     if($name ne ""){
              $msg->attach
               (Type =>$mime->[0],
               Encoding =>$mime->[1],
               Filename =>"$name",
               Path =>"$path",
                  );
     }
     MIME::Lite->send('sendmail',$mailprog);
      $msg->send;
}
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nothing has happened on this question in over 8 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by Wilcoxon.

Please post any comments here within the next seven days. Moderators check comments here before acting on the recommendation. Experts: silence will likely be taken as assent.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer