Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Email HTML

by raveendu.perl (Initiate)
on Jan 11, 2012 at 13:26 UTC ( [id://947342]=perlquestion: print w/replies, xml ) Need Help??

raveendu.perl has asked for the wisdom of the Perl Monks concerning the following question:

Dear friends, I am very new to perl but having lot of intrest to learn. I just tried the below 1. Reading records from database tables and dumping into file 2. Then formating as html page and uploading the data into html page 3. Then sending as email,when i open mail it should appear in the table format with that content. like below. Name Address Number The first two scripts are working fine. But when i run the mail script, it is coming to mail, but not as the expected formate(ie table) its coming as it is html tags and data mingeled. Can someone please help me how to correct this , and what needs to be added to fix this . =================================================
#!/usr/contrib/bin/perl open (HTML, ">/tmp/pperl/index.html"); print HTML "Content-Type: text/html\n\n"; print HTML "<html><head></head><body>"; print HTML "<table border=1>"; print HTML "<tr>"; print HTML "<td width=120 BGCOLOR=#ffff00>Name</td>"; print HTML "<td width=120 BGCOLOR=#ffff00>address</td>"; print HTML "<td width=120 BGCOLOR=#ffff00>number</td>"; print HTML "</tr>\n"; open(INPUTFILE,outfile); open(HTML,">>/tmp/pperl/index.html"); while($line = <INPUTFILE> ) { ($xmit,$dc,$gcd)=split(/,/,$line); print HTML "<tr>"; print HTML "<td>$Name</td>"; print HTML "<td>$address</td>"; print HTML "<td>$number</td>"; print HTML "</tr>"; } close INPUTFILE; print HTML "</table>"; print HTML "</body></html>"; close HTML; ================================================= #!/usr/contrib/bin/perl $to='asmas@xyz.com'; $from= 'asmas@xyz.com'; $subject='First perl HTML Mail test'; open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL "Content-type: text/html\n\n"; open(FILE,"/tmp/pperl/index.html"); print MAIL <FILE>; close (FILE); close(MAIL);
==============================================================

Replies are listed 'Best First'.
Re: Email HTML
by Corion (Patriarch) on Jan 11, 2012 at 13:31 UTC

    Please learn about MIME emails and consider using MIME::Lite for your multipart emails, or use one of the Email modules that support HTML emails.

      Corion thanks for the response. In my machine the MIME::Lite module is not installed ,since i am trying this way. Also i cant install that module as i dont have privilege to install. Pls help me out.
Re: Email HTML
by Utilitarian (Vicar) on Jan 11, 2012 at 13:36 UTC
    Maybe even start with learning about MIME headers...
    print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL "Content-type: text/html\n\n";
    The headers are judged to be complete when a blank line is encountered.

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://947342]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found