Send html mail with perl script

I am working on a unix environment and have a perl script to send mail, but I need to send HTML formatted mail, but it prints like this is html code. so can someone please let me know how he manipulates or compiles html and sends formatted mail.

#!/usr/bin/perl #print "Content-type: text/html\n\n"; print("enter my name"); chop($name=<stdin>); &mail(); sub mail{ $title='perl'; $to=' abcd@acv.com '; $from= ' xyz@xyz.com '; $subject=$name; 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 $name; print MAIL "<html><body><p>"; print MAIL "<b>Hello</b>"; print MAIL "This is a test message from Cyberciti.biz! You can write your"; print MAIL "</p></body></html>"; ##print MAIL "$title"; close(MAIL); } 

His print in the mail:

 <html><body><p><b>Hello</b>This is a test message from Cyberciti.biz! You can write your</p></body></html> 

like this ... because it seems like it is not turning it into html format. So please help me with this.

+4
source share
3 answers

Use Mime :: Lite . This is an example:

 my $msg = MIME::Lite->new( To => ' you@yourhost.com ', Subject => 'HTML example', Type => 'text/html', Data => '<h1>Hello world!</h1>' ); $msg->send(); 
+1
source

The fix for your problem is to add a content header that says the mail is text / html.

But.

  • Please do not send an HTML email address without sending an equivalent text attachment.
  • Please make your life easier with the module. Your best bet is to use the email namespace: *.
  • Please throw away any book that prompts you to call Perl routines using & . It's almost twenty years old.
+2
source

Use Net::SMTP instead

Here is a link that already exists on how to use it in HTML format.

Net :: SMTP using HTML

The same link also shows how you can use Mime :: Lite.

0
source

Source: https://habr.com/ru/post/1486975/


All Articles