I have the following code and am struggling with adding the attachments. can someone please...point me in the right direction.
sub send_mail { my ( %VAR, @atts ); $VAR{sndrEml} = shift; $VAR{sndrNme} = shift; $VAR{rcvrEml} = shift; $VAR{rcvrNme} = shift; $VAR{subject} = shift; $VAR{message} = shift; $VAR{ccrcEml} = shift; $VAR{ccrcNme} = shift; $VAR{attPths} = shift; $VAR{Host} = &gethostname; $CONFIG{mail_format} = 2; $VAR{message} .= qq~\n\nIP Address: $ENV{REMOTE_ADDR}\nHost Node: +$VAR{Host}\nUser Agent: $ENV{HTTP_USER_AGENT}~; if($smtp_path =~ /\w+/){ $CONFIG{mailprogram} = $smtp_path; $CONFIG{mailuser} = $smtp_user; $CONFIG{mailpass} = $smtp_pass; $VAR{res} = &send_mail_NT( $VAR{sndrEml}, $VAR{sndrNme}, $VAR{rcvrEml}, $VAR{rcvrNme}, $VAR{subject}, $VAR{message}, $VAR{ccrcEml}, $VAR{ccrcNme}, $VAR{attPths} ); return $VAR{res}; } else { $CONFIG{mailprogram} = $send_mail_path; } $VAR{CRLF} = "\n"; $VAR{message} =~ s/\r//ig; $VAR{message} =~ s/\n{3,300}/$VAR{CRLF}$VAR{CRLF}/ig; $VAR{message} =~ s/\n/$VAR{CRLF}/ig; $VAR{attPths} =~ s/\s+//ig; $VAR{HTMLmess} = $VAR{message}; $VAR{TEXTmess} = $VAR{message}; if($CONFIG{mail_format} == 2){ $VAR{TEXTmess} =~ s/\&quot;/\"/g; $VAR{TEXTmess} =~ s/\&lt;/\</ig; } $VAR{files} = qq~~; $VAR{hasAtts} = 1; $VAR{sndrNme} =~ s/\&lt;/\</ig; $VAR{rcvrNme} =~ s/\&lt;/\</ig; $VAR{subject} =~ s/\&lt;/\</ig; $VAR{ccrcNme} =~ s/\&lt;/\</ig; $VAR{sndrNme} =~ s/\<.*?>//ig; $VAR{rcvrNme} =~ s/\<.*?>//ig; $VAR{subject} =~ s/\<.*?>//ig; $VAR{ccrcNme} =~ s/\<.*?>//ig; $VAR{bound1} = qq~----=_NextPart_P_115Dream~; # printable $VAR{bound2} = qq~----=_NextPart_A_SubHB~; # attachments $VAR{bound3} = qq~----=_NextPart_E_SlowTrain~; # embded $VAR{fm} = $VAR{sndrNme} =~ /\w+/ ? qq~$VAR{sndrEml} ($VAR{sndrNme +})~ : $VAR{sndrEml}; $VAR{to} = $VAR{rcvrNme} =~ /\w+/ ? qq~$VAR{rcvrEml} ($VAR{rcvrNme +})~ : $VAR{rcvrEml}; $VAR{cc} = $VAR{ccrcNme} =~ /\w+/ ? qq~$VAR{ccrcEml} ($VAR{ccrcNme +})~ : $VAR{ccrcEml}; if(open(M, qq~|$CONFIG{mailprogram} -t ~)){ print M qq~From: $VAR{fm}$VAR{CRLF}~; print M qq~To: $VAR{to}$VAR{CRLF}~; print M qq~CC: $VAR{cc}$VAR{CRLF}~ if $VAR{ccrcEml}; print M qq~Subject: $VAR{subject}$VAR{CRLF}~; print M qq~MIME-Version: 1.0$VAR{CRLF}~; if($CONFIG{mail_format} == 1){ print M qq~$VAR{fileHeaders}~; print M qq~$VAR{embedHeaders}~; print M qq~Content-Type: multipart/alternative;$VAR{CRLF}~ +; print M qq~\tboundary="$VAR{bound1}"$VAR{CRLF}$VAR{CRLF}$V +AR{CRLF}~; print M qq~--$VAR{bound1}$VAR{CRLF}~; print M qq~Content-Type: text/plain;$VAR{CRLF}~; print M qq~Content-Transfer-Encoding: 7bit$VAR{CRLF}$VAR{C +RLF}~; print M qq~$VAR{TEXTmess}$VAR{CRLF}$VAR{CRLF}~; print M qq~--$VAR{bound1}$VAR{CRLF}~; print M qq~Content-Type: text/html; $VAR{charset2}$VAR{CRL +F}$VAR{CRLF}~; print M qq~$VAR{HTMLmess}$VAR{CRLF}~; print M qq~$VAR{CRLF}$VAR{CRLF}--$VAR{bound1}--$VAR{files} +~; } else { print M qq~$VAR{fileHeaders}~; print M qq~Content-Type: text/plain;$VAR{CRLF}~; print M qq~Content-Transfer-Encoding: 7bit$VAR{CRLF}$VAR{C +RLF}~; print M qq~$VAR{TEXTmess}$VAR{CRLF}$VAR{CRLF}$VAR{files}~; } close M; return 1; } else { return; } }

In reply to How to add attachments to an email using cgi/perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.