#!/usr/bin/perl # # SendMail.cgi -- This is a perl CGI script which is using SendMail.pm # module to send the submitted data. # It does not need any sendmail program, just needs the # SendMail.pm. And it works in both UNIX and Windows # platforms. But it require perl version 5. # Source code for this cgi script and SendMail.pm can # be downloaded at # http://www.tneoh.zoneit.com/perl/SendMail/ # If you are on Windows platform, make sure your machine # is the SMTP server itself, else instead of using # $sm = new SendMail(); # change it to: # $sm = new SendMail($smtpserver); # And for Windows platform users, make sure you have # used a correct perl path at the first line of this # CGI script. It should be something like: # #!C:/perl5/perl-5.000/perl/bin/perl.exe # # Simon Tneoh Chee-Boon tneohcb@pc.jaring.my # # Copyright (c) 1998,1999 Simon Tneoh Chee-Boon. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # # Please refer to http://www.tneoh.zoneit.com/perl/CGI_LIB/ # use CGI_LIB; # # Please refer to http://www.tneoh.zoneit.com/perl/SendMail/ # use SendMail; use strict; $| = 1; my($sender) = "Simon Tneoh Chee-Boon "; my($subject) = "Thanks for testing SendMail.cgi"; my($errorsto) = $sender; my($replyto) = $sender; my($cgiObj) = new CGI_LIB; print "Content-Type: text/html\n\n"; my($recipient) = "$cgiObj->{'username'} <$cgiObj->{'email'}>"; my($sm) = new SendMail("your.smtp.server"); $sm->From($sender); $sm->To($recipient); $sm->ReplyTo($sender); $sm->ErrorsTo($errorsto); $sm->Subject($subject); $sm->setMailHeader("URL", "http://www.tneoh.zoneit.com/perl/SendMail/"); my($mailbody) = <<__END__MAILBODY__; Dear $cgiObj->{'username'}, Thanks for testing the SendMail.cgi CGI script. You have submitted the following information: Your Name: $cgiObj->{'username'} Your Email Add.: $cgiObj->{'email'} Your Message: $cgiObj->{'message'} Regards, -- Simon Tneoh Chee-Boon Application Developer Hitechniaga Sdn. Bhd. tneohcb\@pc.jaring.my 60-3-9660966 http://www.tneoh.zoneit.com/simon/ __END__MAILBODY__ $sm->setMailBody($mailbody); if ($sm->sendMail() != 0) { printError($sm->{'error'}); exit; } printThankYou(); # # You can uncomment the following four lines if you're on # UNIX platform. # #my($pid) = fork; #$pid = 0 unless defined $pid; #exit 0 if $pid; #close(STDOUT); # # Now send the submitted data to the sender. # # # We reset the SendMail object to clear the data that we have set # into the object, like sender, recipient, subject and etc. # $sm->reset(); my($script) = "SendMail.cgi Script "; $replyto = "$cgiObj->{'username'} <$cgiObj->{'email'}>"; $recipient = $sender; $subject = "User tested SendMail.cgi."; $sm->From($script); $sm->Subject($subject); $sm->To($recipient); my($localtime) = scalar(localtime()); $mailbody = <<__END__MAILBODY__; Time: $localtime User Name: $cgiObj->{'username'} User Email Add.: $cgiObj->{'email'} User Message: $cgiObj->{'message'} __END__MAILBODY__ $sm->setMailBody($mailbody); if ($sm->sendMail() != 0) { printError($sm->{'error'}); exit; } exit 0; sub printError { my($error) = shift; print <<__END__ERROR__; Error

Error


$error

Please click here to try again.


__END__ERROR__ return 0; } sub printThankYou { print <<__END__THANKYOU__; Thank You

Thank You


Dear $cgiObj->{'username'},

Thanks for testing.

You submission has been sent to me and make a copy to you.

Please click here to go back to SendMail.pm demonstration page.


__END__THANKYOU__ return 0; }