Sending an Email using MIME protocol

Hi All,

I just need to send an email using MIME protocol from perl script. The data of an email should be a HTML table(contains some datas). I just tried to send a normal text which is working fine whereas if i insert HTML tags i am getting errors. I just tried like below

$mail_host = "mailhost";
$to = "abc@gmail.com";
$from = "def@gmail.com";
$subject = "Workign of MIME";
$data =
"<html>
<body>
<table>
<tr>
<td> Name: </td>
<td> </td>
</tr>        
<tr>
<td> Age: </td>
<td>  </td>
</tr> 
<tr>
<td> Location: </td>
<td> </td>
</tr> 
</body>
</html>"
$msg = MIME::Lite->new (
From => $from,
To => $to,
Subject => $subject,
);
$msg->attach (
Content-Type: text/html; charset="UTF-8"
Data => $data
);
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;
 

Thanks in advance!!

Your $data string should have a semicolon.

$data = '<html>
<body>
<table>
<tr>
<td> Name: </td>
<td> </td>
</tr>        
<tr>
<td> Age: </td>
<td>  </td>
</tr> 
<tr>
<td> Location: </td>
<td> </td>
</tr> 
</body>
</html>';

Hi Rajamadhavan,

My code is below.

$Data = "<html>
<head>
</head>
<body>
<table border=1  cellspacing=0 cellpadding=0 width=85%>
<tr style="text-align:center bgcolor=brown" font-color:>
<td colspan="2" width="97%"  style="line-height:115%"><b><font size="5" color="white" face="Arial"><span style="font-size:16.0pt;line-height:115%;font-family:Arial;color:white;font-weight:bold"> EMPLOYEEE DATABASE </span></font></b></td>
</tr>
<tr>
<td width="24%" height="30%" bgcolor="green" style="text-align:right"><b> <font size="3" color="black" face="Arial"><b><font> <span style="font-size:11.0pt;line-height:115%;font-family:Arial;color:black;font-weight:bold"> Name:</span> </font></b> </td>
<td><font size="3" color="black" face="calibri"> ABCDE </font></td>
</tr>
<tr>
<td bgcolor="#93FFC4" style="text-align:right"><b><font size="3" color="black" face="Arial"> <span style="font-size:11.0pt;line-height:115%;font-family:Arial;color:black;font-weight:bold">AGE </span></font></b> </td>
<td><font size='3' color='black' face='calibri'> 152 </font></td>
</tr>
</table>
</body>
</html>";

If i execute the script i m just getting erros like "Bareware found where operator expected" in most of the lines.

Your data has several characters without any escape that perl interprets differently. Please use this way

$Data = <<EOF;
<html>
<head>
</head>
<body>
<table border=1  cellspacing=0 cellpadding=0 width=85%>
<tr style="text-align:center bgcolor=brown" font-color:>
<td colspan="2" width="97%"  style="line-height:115%"><b><font size="5" color="white" face="Arial"><span style="font-size:16.0pt;line-height:115%;font-family:Arial;color:white;font-weight:bold"> EMPLOYEEE DATABASE </span></font></b></td>
</tr>
<tr>
<td width="24%" height="30%" bgcolor="green" style="text-align:right"><b> <font size="3" color="black" face="Arial"><b><font> <span style="font-size:11.0pt;line-height:115%;font-family:Arial;color:black;font-weight:bold"> Name:</span> </font></b> </td>
<td><font size="3" color="black" face="calibri"> ABCDE </font></td>
</tr>
<tr>
<td bgcolor="#93FFC4" style="text-align:right"><b><font size="3" color="black" face="Arial"> <span style="font-size:11.0pt;line-height:115%;font-family:Arial;color:black;font-weight:bold">AGE </span></font></b> </td>
<td><font size='3' color='black' face='calibri'> 152 </font></td>
</tr>
</table>
</body>
</html>
EOF