Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Is there any way to send HTML table information

by Anonymous Monk
on Mar 14, 2007 at 03:49 UTC ( [id://604731]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
Is there any way to send HTML table information through mail ?
I have a html page (which is dynamically generated by a perl program), when I submit the form, it will call a perl program that will send the table information from the html page.

How can I send this table info to perl program? or Is there any way to get a solution?

For example, In some site, if we wan to send article, we can see an option say do you want to send this page to friends.
When we input friends email address and click on SEND button, the artcle (from html page) will send to as html format to the mail addresses.
The same kind of output I am looking for my question.

Could you please send me the sample code
here is my sample page
<HEAD> <TITLE> Test </TITLE> </HEAD> <BODY> <form name="mailform" method="post" action="mail.pl"> <div id="mailcontent"> <TABLE width="100%" border=1 cellpadding=0 cellspacing=0> <TR> <TD>Account No</TD> <TD>Type</TD> <TD>Branch</TD> </TR> <TR> <TD>11111111</TD> <TD>Savings</TD> <TD>Branch1</TD> </TR> <TR> <TD>2222222</TD> <TD>Current</TD> <TD>Branch2</TD> </TR> <TR> <TD>3333333</TD> <TD>Savings</TD> <TD>Branch3</TD> </TR> </TABLE> </div> <br> To :&nbsp;<input type="text" name="to" size="10"><br> <center><input type="submit" name="mail" value="Send Mail"></center> </form> </BODY> </HTML>
Thanks

Replies are listed 'Best First'.
Re: Is there any way to send HTML table information
by hacker (Priest) on Mar 14, 2007 at 04:16 UTC

    Keep the HTML on port 80 and the SMTP on port 25 please. We have enough trouble with people misusing email already.

    Many people are stripping HTML out of email anyway, server-side, with milters and other tools, because of the dangerous nature of malware, web-bugs and other malicious "crumbs" that find their way through HTML-laden email.

    There's no way to reliably guarantee that the recipient is going to be displaying the email in the way you intend. Are they using Outlook? pine? mutt? Evolution? KMail? Other?

    The right way to do this, is to use Text::xSV, Text::CSV, Spreadsheet::WriteExcel or similar modules. Send the data across in a way that can be used on the other side, and not just displayed in a browser on the other side.

    If you must display HTML (and please, please please validate it!), just send the URL in an email, where the reader can launch it in their browser of choice to display it.

Re: Is there any way to send HTML table information
by marto (Cardinal) on Mar 14, 2007 at 08:53 UTC
    If you have to (as you have been told a lot of people bin such messages without reading them) send html via email you may want to take a look at MIME::Lite and The Perl Email Project.

    Hope this helps

    Martin
Re: Is there any way to send HTML table information
by jonsmith1982 (Beadle) on Mar 14, 2007 at 04:14 UTC
    i would use a hidden field of the absolute url from which you can make mail.pl connect to 127.0.0.1 and retrieve the table data and send in an email or better yet use a hidden field relating to a database item.
Re: Is there any way to send HTML table information
by ww (Archbishop) on Mar 14, 2007 at 12:51 UTC
    Knowing that I'm beating a dead horse, here, "don't do it!"

    As noted above, there are many, many arguements against using html in mail, and precious few (IMO) in favor of using it.

    But, more to the point
    This is perlmonks; and a quick look at How do I post a question effectively? suggests several improvements to your question

    • Show us some (Perl} code (or at least show us your mail.pl code.)
    • Tell us why what appears to be financial data needs to be transmitted as a webpage.
    And,
    • Welcome to the Monastery, and...
    • for whatever its worth, why don't you create an account here?
    Update: fixed missing close_paren, missing period
Re: Is there any way to send HTML table information
by radiantmatrix (Parson) on Mar 14, 2007 at 20:50 UTC
    I have a html page (which is dynamically generated by a perl program),

    Before worrying about how to convert the table on a page to an e-mailable format, have you considered modifying the generator to make your life easier?

    If you store the results in a CSV file (check out File::Temp for one good method of making sure the name is unique, and Text::CSV_XS for making the CSV file) right before you send the HTML table out, then reference the file name in the HTML form (as a hidden element), you can have the mail-sending program attach said file to the message (check out MIME::Lite for that). Once you're there, you could even add the option to download said CSV file instead of having it mailed.

    Since CSV files will typically open in a spreadsheet application on the users' computer (if the user is savvy enough to change that, they probably know how to deal with CSVs anyhow), it makes for a pretty nice interface.

    What you don't want to do is e-mail the HTML verbatim; as others have pointed out, it will often be filtered away and/or irritate the recipient.

    If you really can't modify the program that builds the page to start with, you could use LWP from your mailing program to retrieve the page, and something like HTML::TokeParser to get the data back into a Perl data structure. Then, either write out a text-only table (see format and write, or just use Text::Table), or generate and attach a CSV as above.

    Just be sure of your real requirements before pursuing things too far.

    <radiant.matrix>
    Ramblings and references
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet
      radiantmatrix,
      Well Explained ...
      Thanks a lot for your help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-04-19 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found