#===============================================================# # sendemail.pl # # send_email() Version 1.0 # # Copyright by Terra terra@ps.inforyoma.or.jp # # # # Usage: &send_email($subject, $from, $to, $cc, $bcc) # # # # Variables: $subject -- 件名 # # $from -- 差出人メールアドレス # # $to -- 送信先メールアドレス # # $cc -- カーボンコピー # # $bcc -- ブラインドカーボンコピー # # $body -- 本文 # # Returns: 0 送信に成功した # # 1 送信に失敗した # # # # global $sendmail # # このグローバル変数にsendmailのパスを指定 # #===============================================================# sub send_email { local($subject, $from, $to, $cc, $bcc, $body, $file) = @_; local(@TO) = split(/\,/, $to); local(@CC) = split(/\,/, $cc); local(@BCC) = split(/\,/,$bcc); local($attach_file) = ''; local($mailto) = ''; local($i); $i = 1; foreach $ml (@TO, @CC, @BCC) { if ($ml =~ /([#-9A-~\-\_]+\@[#-9A-~\-\_\.]+)/) { if ($i == 1) { $mailto = "$1"; } else { $mailto .= "\,$1"; } } $i++; } if (!$mailto) { return(1); } if (!open(MAIL,"| $sendmail -t -n -oi $mailto")) { return(1); } print MAIL "FormMailer: FormMail v1.5\n"; if (!$bcc) { print MAIL "To: $to\n"; } print MAIL "From: $from\n"; print MAIL "CC: $cc\n" if $cc; print MAIL "Subject: $subject\n"; print MAIL "Content-Transfer-Encoding: 7bit\n"; print MAIL "Content-Type: text/plain;\n\n"; print MAIL $body; print MAIL "\n"; if ($file ne '') { if (-e $attach_file) { if (!open(TEXT, $file)) { return(1); } print MAIL "Attachment: $file\n"; print MAIL "Encoding: None\n\n"; while () { print MAIL; } close(TEXT); print MAIL "\n\n"; } } close(MAIL); 0; } 1;