CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Basic Email Sending Format

 



ImustDIE
Novice

Jan 2, 2001, 9:56 PM

Post #1 of 4 (309 views)
Basic Email Sending Format Can't Post

Im writing a script and i cant seem to get it to work right.... whats the basic format for sending an email thru a cgi script.



BigRich
Novice

Jan 3, 2001, 1:03 AM

Post #2 of 4 (306 views)
Re: Basic Email Sending Format [In reply to] Can't Post

If you have access to sendmail, all you need to know is the path and the rest is basically the same as printing to a file. Just be sure to include the "To:" and "From:" fields.

my $mail_program = '/usr/lib/sendmail';
my $from_address = "me\@my_isp.com";
my $to_address = "you\@your_isp.com";

open(MAIL, "| $mail_program") || die "Could not open sendmail: $!";
print MAIL "To: $to_address \n";
print MAIL "From: $from_address \n";
print MAIL "Subject: This is a test of sendmail\n\n";
print MAIL "This is the main body of your message.";
close(MAIL);

print "Mail has been sent.";

If you're not sure of the path to your mail program or are not certain of the procedure for accessing it, ask the server admin at your site's host.

Good luck,

Rich



ImustDIE
Novice

Jan 3, 2001, 4:47 PM

Post #3 of 4 (302 views)
Re: Basic Email Sending Format [In reply to] Can't Post

im gonna kill myself soon if i cant get this to work!
i have this exact code in my script, i know thats the right path... but it still refrains from working.

my $mail_program = '/usr/bin/sendmail';
my $from_address = "cnc2dude\@earthlink.net";
my $to_address = "cnc2dude\@earthlink.net";

open(MAIL, "| $mail_program") || die "Could not open sendmail: $!";
print MAIL "To: $to_address \n";
print MAIL "From: $from_address \n";
print MAIL "Subject: This is a test of sendmail\n\n";
print MAIL "This is the main body of your message.";
close(MAIL);


is there an error anywhere? ive tried it on multiple servers and tried to get soem of my friends to help me but i couldnt find the problem!



BigRich
Novice

Jan 3, 2001, 7:43 PM

Post #4 of 4 (296 views)
Re: Basic Email Sending Format [In reply to] Can't Post

There is a typo in my other post, open(MAIL, "| $mail_program") should be open(MAIL, "|$mail_program -t") .

If you are certain of the path, then try the script below (I used it with my info to send a test mail to myself before posting it). If it doesn't help, then contact some one at your site host as they are in the best position to tell you how their mail program works. There is no single method of sending mail using a "sendmail" program. The one I'm giving is just one of the more common.

#!/usr/bin/perl -w

print "Content-type: text/html\n\n";

open(MAIL, "|/usr/bin/sendmail -t") || &error("Could not open sendmail: $!");
print MAIL "To: cnc2dude\@earthlink.net\n";
print MAIL "From: cnc2dude\@earthlink.net\n";
print MAIL "Subject: This is a test\n\n";
print MAIL "Sendmail OK\n\n";
close(MAIL);

print"Mail Sent !";

sub error {
print @_;
exit;
}
__END__



Good luck,

BigRich


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives