Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
sub my_sendmail { my ($to, $subject, $msg_body, $from_addr, $from_name, $to_name) = @_ +; my $input; # Make sure variables are set up correctly (ref($to) eq "ARRAY") || die "Argument \$to must be a reference to a +n array"; $subject = "(No subject)" unless ($subject); # Add the first email address to the To: name $to_name = ($to_name ? "$to_name " : ''); $to_name .= "<$to->[0]>"; # Use default 'from' address if not defined unless ($from_addr) { $from_addr = $default_from_addr; $from_name = $default_from_name; } # Add 'from' address to name. Some ISP's require a valid email in ' +From:' $from_name .= " <$from_addr>"; warn "<pre>\n" if ($sendmail_debug); warn "Calling SMTP server.\n" if ($sendmail_debug); my $sock = IO::Socket::INET->new( PeerAddr => $mail_server, Type => SOCK_STREAM, PeerPort => 'smtp(25)', Proto => 'tcp'); unless ($sock) { warn "Can't open a port on the mail server ($mail_server)."; return 0; } $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); print $sock "HELO localhost\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); print $sock "mail from:<$from_addr>\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); # Send to each recipient here. They won't see the others' addresses my $rcpt; foreach $rcpt (@$to) { print $sock "rcpt to:<$rcpt>\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); } print $sock "DATA\r\n"; print $sock "Subject: $subject\r\n"; print $sock "From: $from_name\r\n"; print $sock "Reply-To: $from_addr\r\n"; print $sock "To: $to_name\r\n"; print $sock "\r\n"; #test line to add HTML to the emails print $sock "Content-type: text/plain\n\n"; print $sock "$msg_body\r\n"; print $sock ".\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); print $sock "QUIT"; close ($sock); return 1; } # End of my_sendmail() 1; # End of My Sendmail.pm __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending HTML emails HELP!
by zentara (Cardinal) on Nov 25, 2008 at 18:06 UTC | |
|
Re: Sending HTML emails HELP!
by oeuftete (Monk) on Nov 25, 2008 at 17:07 UTC | |
by Anonymous Monk on Nov 25, 2008 at 17:24 UTC | |
by jdrago_999 (Hermit) on Nov 25, 2008 at 17:33 UTC | |
by Anonymous Monk on Nov 25, 2008 at 18:20 UTC |