Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: html format email

by GordonLim (Acolyte)
on Apr 05, 2013 at 19:35 UTC ( #1027207=note: print w/ replies, xml ) Need Help??


in reply to Re: html format email
in thread html format email

Hi, Finally I successed to print out html formal table. But now I'm facing another new problem is how to add function in the html? exmaple add in foreach function or I try to add

open(INFO, "data2.txt"); # Open db for reading @array=<INFO>; close (INFO); @ascend=sort(@array);
it just display this code out and not working as function. below is my example script:
my $data = qq{ open(INFO, "data2.txt"); # Open db for reading @array=<INFO>; close (INFO); @ascend=sort(@array); <h1 border=\"1\" align=\"center\">Welcome to ATCA Booking and man +agment system<br>Chassis information and detail</h1> <body> <TABLE cellSpacing=\"0\" cellPadding=\"0\" border=\"1\" align=\"c +enter\"> <TR align=\"center\"><TD>No</TD><TD>version</TD><TD>Chassis</TD><T +D>Assigned</TD><TD>CMMIP1</TD><TD>CMMIP2</TD><TD>CMM1<br>SerialPortCo +nnection</TD><TD>CMM2<br>SerialPortConnection</TD><TD>Ibootbar_Altuse +n</TD></TR> foreach $line (@ascend){ ($version,$okok)=split(/\|/,$line); <TR><TD align=\"center\"> $i++ </TD><TD> $version </TD> } </table> };


Comment on Re^2: html format email
Select or Download Code
Re^3: html format email
by golux (Pilgrim) on Apr 05, 2013 at 19:42 UTC
    You've mixed data and code, which won't work. Perhaps you're confusing perl with php?

    What you want to do is separate the data and code, having the code process the data. Something like:

    use strict; use warnings; my $data = qq{ <h1 border=\"1\" align=\"center\">Welcome to ATCA Booking and man +agment system<br>Chassis information and detail</h1> <body> <TABLE cellSpacing=\"0\" cellPadding=\"0\" border=\"1\" align=\"c +enter\"> <TR align=\"center\"><TD>No</TD><TD>version</TD><TD>Chassis</TD><T +D>Assigned</TD><TD>CMMIP1</TD><TD>CMMIP2</TD><TD>CMM1<br>SerialPortCo +nnection</TD><TD>CMM2<br>SerialPortConnection</TD><TD>Ibootbar_Altuse +n</TD></TR> </table> }; # Open db for reading -- but die if there's an error open(INFO, "data2.txt") or die "Failed to open 'data2.txt' ($!)\n"; my @array = <INFO>; close (INFO); my @ascend=sort(@array); my $i = 1; foreach my $line (@ascend){ my ($version, $okok) = split(/\|/,$line); $data .= qq{ <TR><TD align=\"center\"> $i </TD><TD> $version </TD> }; ++$i; } print "DATA:\n $data\n";

    Update: put back $i, which I now see was in each first <td>

    say  substr+lc crypt(qw $i3 SI$),4,5
      Hi, Finally I done my table, thank you very much to golux. Below are the script working for me :)
      my $data = qq{ Hi All,<br> Currently below are the chassis which is currently being assigned <TABLE cellSpacing=\"0\" cellPadding=\"0\" border=\"1\" align=\"c +enter\"> <TR align=\"center\"><TD>No</TD><TD>version</TD><TD>Chassis</TD><T +D>Assigned</TD><TD>CMMIP1</TD><TD>CMMIP2</TD><TD>CMM1<br>SerialPortCo +nnection</TD><TD>CMM2<br>SerialPortConnection</TD><TD>Ibootbar_Altuse +n</TD></TR> }; # Open db for reading -- but die if there's an error open(INFO, "data.txt")or die "Failed to open 'data.txt' ($!)\n"; # + Open db for reading @array = <INFO>; close (INFO); @ascend=sort(@array); foreach my $line (@ascend){ my($version,$Chassis,$Assigned,$CMMIP1,$CMMIP2,$CMM1SerialPortConn +ection,$CMM1SerialPortConnectionPort,$CMM2SerialPortConnection,$CMM2S +erialPortConnectionPort,$Ibootbar_Altusen) = split(/\|/,$line); $data .= qq{ <TR><TD align=\"center\"> $i </TD><TD> $version </TD><TD> $Chassis </TD><TD> $Assigned </TD><TD> $CMMIP1 </TD><TD> $CMMIP2 </TD><TD> $CMM1SerialPortConnection <h>Port-</h> $CMM1SerialPortConnectionPort </TD><TD> $CMM2SerialPortConnection <h>Port-</h> $CMM2SerialPortConnectionPort </TD><TD> $Ibootbar_Altusen </TD></TR> }; ++$i; } print "DATA:\n $data\n"; my $mime = MIME::Lite->new( 'From' => $sender, 'To' => $email, 'Subject' => $subject, 'Type' => 'text/html', 'Data' => $data, ); $pingStatus = &checkTargetPing("mail.hotmail.com"); if ($pingStatus eq 1) { $smtp = Net::SMTP->new('mail.hotmails.com'); $mime->send() or die "Failed to send mail\n"; $mime->quit; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027207]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-12-27 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls