Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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/\"/\"/g; $VAR{TEXTmess} =~ s/\</\</ig; } $VAR{files} = qq~~; $VAR{hasAtts} = 1; $VAR{sndrNme} =~ s/\</\</ig; $VAR{rcvrNme} =~ s/\</\</ig; $VAR{subject} =~ s/\</\</ig; $VAR{ccrcNme} =~ s/\</\</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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to add attachments to an email using cgi/perl
by hangon (Deacon) on Aug 10, 2009 at 05:46 UTC | |
|
Re: How to add attachments to an email using cgi/perl
by roboticus (Chancellor) on Aug 10, 2009 at 12:40 UTC | |
by ig (Vicar) on Aug 10, 2009 at 21:18 UTC |