Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Quick and Dirty Everyday Email Subroutine

by p3rl (Novice)
on Jun 16, 2001 at 09:58 UTC ( [id://89017]=CUFP: print w/replies, xml ) Need Help??

Just a simple subroutine that I have been using as a novice perl programmer. I know that it is not fully optioned and that many other libraries offer better email functionality but I think that it works great for me and I have reused it over and over, so for other novices like me out there here you go. To use it just cut and paste it into your script, call it by using &email(mail_prog,to,from,subject,body); the fields I guess explain themselves PS. you dont have to worry about assigning different variable names because it uses local varible names that are contained in the subroutine.
sub email { local($mail_prog, $to, $from, $subject, $body) = @_; open(MAIL, "|$mail_prog -t"); print MAIL "To: $to \n"; print MAIL "From: $from \n"; print MAIL "Subject: $subject \n\n"; print MAIL "$body"; print MAIL "\n\n"; close (MAIL); }

Replies are listed 'Best First'.
Re: Quick and Dirty Everyday Email Subroutine
by ZZamboni (Curate) on Jun 16, 2001 at 21:41 UTC
    Sorry for being picky, but I just want to point out that something like this is OK for "quick and dirty" stuff (I used something similar here), but only if you have absolute control over the contents of $mail_prog. Otherwise, it would be very easy for someone to do very nasty things using that variable and the open.

    --ZZamboni

Re: Quick and Dirty Everyday Email Subroutine
by p3rl (Novice) on Jun 18, 2001 at 13:24 UTC
    I see what you mean

    You are right, but when I use this code i have a varible $mail_prog at the top of the script.

    True if you take it as input from a form it can be quite dangerous.

    Like:

    #!/usr/bin/perl ....... $mail_prog = "/usr/bin/sendmail"; ....... Call Email Subroutine here. ........

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://89017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-25 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found