# Sending a Plain Message using Perl

PERLServer Side ProgrammingProgramming Scripts

If you are working on Linux/Unix machine then you can simply use sendmail utility inside your Perl program to send email. Here is a sample script that can send an email to a given email ID. Just make sure the given path for sendmail utility is correct. This may be different for your Linux/Unix machine.

#!/usr/bin/perl
$to = 'abcd@gmail.com';$from = 'webmaster@yourdomain.com';
$subject = 'Test Email';$message = 'This is test email sent by Perl Script';
open(MAIL, "|/usr/sbin/sendmail -t");

print MAIL "To: $to\n"; print MAIL "From:$from\n";
print MAIL "Subject: $subject\n\n"; # Email Body print MAIL$message;
print "Email Sent Successfully\n";