468,456 Members | 1,719 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,456 developers. It's quick & easy.

change script to send html email

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
1 1730
gpraghuram
1,275 Expert 1GB
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.

Similar topics

6 posts views Thread by Jeff Dunnett | last post: by
3 posts views Thread by bigoxygen | last post: by
4 posts views Thread by Richard Cornford | last post: by
5 posts views Thread by Iver Erling Årva | last post: by
11 posts views Thread by cybervigilante | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.