By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

change script to send html email

P: 9
hello all,

i need help modifying a small perl script that sends an email after a form is submitted.
i need to be able to receive the email in html format, but my knwoledge of perl is very poor.

please any help at this moment would be fantastic.

thank you.

here is my script:
Expand|Select|Wrap|Line Numbers
  1. l#!/usr/bin/perl -w
  2.  
  3. use Net::SMTP;
  4. use CGI;
  5.  
  6. my $cgi = new CGI;
  7.  
  8. sub send_mail 
  9.  
  10. {
  11.     my $to = $_[0];
  12.     my $subject = $_[1];
  13.     my $body = $_[2];
  14.      my $from = $_[3];
  15.  
  16.     my $smtp;
  17.  
  18. if (not $smtp = Net::SMTP->new('mail.server.com', Port => 25, Debug => 1)) 
  19. {
  20.     die "Could not connect to server\n";
  21. }
  22.  
  23. $smtp->mail($from . "\n");
  24.  
  25. my @recepients = split(/,/, $to);
  26.  
  27. foreach my $recp (@recepients) 
  28. {
  29.     $smtp->to($recp . "\n");
  30. }
  31.  
  32. $smtp->data();
  33. $smtp->datasend("From: " . $from . "\n");
  34. $smtp->datasend("To: " . $to . "\n");
  35. $smtp->datasend("Subject: " . $subject . "\n");
  36. $smtp->datasend("\n");
  37.  
  38. $smtp->datasend($body . "\n");
  39. $smtp->dataend();
  40. $smtp->quit;
  41. }
  42. # Send away!
  43. &send_mail($cgi->param('to'), $cgi->param('subject'), $cgi->param('body'), $cgi->param('from'));
  44.  
  45. print $cgi->header;
  46. print '<html><body>Your e-mail has been sent</body></html>';
  47.  
Jun 17 '08 #1
Share this Question
Share on Google+
1 Reply


gpraghuram
Expert 100+
P: 1,275
You can use MIME::Lite to do this
See this sample code
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use MIME::Lite;
  3.  
  4. # SendTo email id
  5. my $to_id = 'yourid@mail.com';
  6.  
  7. # create a new MIME Lite based email
  8. my $msg = MIME::Lite->new
  9. (
  10. Subject => "HTML Mail",
  11. From    => 'yyy@zzz.com',
  12. To      => $to_id,
  13. Type    => 'text/html',
  14. Data    => '<H1>Hello</H1><br>This is sample html mail.<br>'
  15. );
  16.  
  17. $msg->send();
  18.  
  19.  
Raghu
Jun 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.