Q. How can I send an email with perl?
A. With the help of sendmail you can send an email from your web based feedback form. You will need to indicate the path to the mail program, Sendmail. Usually the path to Sendmail is /usr/sbin/sendmail. Here is sample script that can send an email to your account or to end user. Make sure you setup
$to='MAIL ADDRESS TO SEND TO';
Here is sample script to sending an email using perl [ Download script ]:
#!/usr/bin/perl print "Content-type: text/html\n\n"; $title='Perl Mail demo'; $to='MAIL ADDRESS TO SEND TO'; $from= 'webmaster@YOURDOMAIN.COM'; $subject='YOUR SUBJECT'; open(MAIL, "|/usr/sbin/sendmail -t"); ## Mail Header print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; ## Mail Body print MAIL "This is a test message from Cyberciti.biz! You can write your mail body text here\n"; close(MAIL); print "<html><head><title>$title</title></head>\n<body>\n\n"; ## HTML content sent, let use know we sent an email print "<h1>$title</h1><p>A message has been sent from $from to $to</p></body></html>";
Upload script Upload script to your web hosting cgi-bin directory. Then test is by typing url. For example http://mydomain.com/cgi-bin/sendmail.pl.
Caution: Notice that the subject line in the above script ends with two \n (new line) characters. These characters are required to separate the email header from the email body with a blank line. Do not remove them.Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?
- 30 Cool Open Source Software I Discovered in 2013
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012
- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop