•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 423,610 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,210 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 1282 | Replies: 1
![]() |
•
•
Join Date: Aug 2006
Posts: 999
Reputation:
Rep Power: 4
Solved Threads: 1
I am trying to program a work-related report system. The reports are generated in php, and I have been requested to have the results sent via email to the individual who needs to review them. (That is, one person generates the reports to look at via an external program, but another person also needs to review them and gets the results in email.)
I found a mailing script we use for something else, and thought I'd managed to modify it for my purposes, but I keep running into a rather strange problem. I'm trying to send an html message to the user's inbox; instead of being the body of the email, the message is being added as an attachment. The original program I modified was designed to send a message and a file; I thought I'd gotten rid of the file-sending portion, but apparently I am incorrect in this.
The code below is a copy of the script I'm using:
Can anyone see what I've done wrong in here, that it keeps sending the message as an attachement instead of as the email body?
Please note: the email addresses aren't listed correctly here. I starred them out since I'm testing on my own work email and want to leave as few instances of that out on the web to become spambait as possible. The actual addresses are valid.
I found a mailing script we use for something else, and thought I'd managed to modify it for my purposes, but I keep running into a rather strange problem. I'm trying to send an html message to the user's inbox; instead of being the body of the email, the message is being added as an attachment. The original program I modified was designed to send a message and a file; I thought I'd gotten rid of the file-sending portion, but apparently I am incorrect in this.
The code below is a copy of the script I'm using:
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Net::SMTP;
use MIME::Lite;
my $from_address = '******@*******.com';
my $to_address = '******@*******.com';
my $mail_host = 'mail.hiwaay.net';
my $msg;
print "Sending email from $from_address\nto $to_address via $mail_host\n\n";
my $subject = 'Test Report';
my $message_body = '<TABLE BORDER=2 RULES=2 GROUPS WIDTH=90%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION><TR><TD ALIGN=RIGHT>Company Totals</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total $</TD></TR></TBODY></TABLE>';
$msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
Type => 'text/html',
Data => $message_body
) or die "$!\n";
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;Can anyone see what I've done wrong in here, that it keeps sending the message as an attachement instead of as the email body?
Please note: the email addresses aren't listed correctly here. I starred them out since I'm testing on my own work email and want to leave as few instances of that out on the web to become spambait as possible. The actual addresses are valid.
Last edited by EnderX : Sep 10th, 2007 at 1:29 pm.
"No trees were harmed in the production of this post. However, several electrons were severely inconvenienced."
Kumquat.
Kumquat.
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation:
Rep Power: 2
Solved Threads: 20
•
•
•
•
I am trying to program a work-related report system. The reports are generated in php, and I have been requested to have the results sent via email to the individual who needs to review them. (That is, one person generates the reports to look at via an external program, but another person also needs to review them and gets the results in email.)
I found a mailing script we use for something else, and thought I'd managed to modify it for my purposes, but I keep running into a rather strange problem. I'm trying to send an html message to the user's inbox; instead of being the body of the email, the message is being added as an attachment. The original program I modified was designed to send a message and a file; I thought I'd gotten rid of the file-sending portion, but apparently I am incorrect in this.
The code below is a copy of the script I'm using:
#!/usr/bin/perl use strict; use warnings; use diagnostics; use Net::SMTP; use MIME::Lite; my $from_address = '******@*******.com'; my $to_address = '******@*******.com'; my $mail_host = 'mail.hiwaay.net'; my $msg; print "Sending email from $from_address\nto $to_address via $mail_host\n\n"; my $subject = 'Test Report'; my $message_body = '<TABLE BORDER=2 RULES=2 GROUPS WIDTH=90%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION><TR><TD ALIGN=RIGHT>Company Totals</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total $</TD></TR></TBODY></TABLE>'; $msg = MIME::Lite->new ( From => $from_address, To => $to_address, Subject => $subject, Type => 'text/html', Data => $message_body ) or die "$!\n"; MIME::Lite->send('smtp', $mail_host, Timeout=>60); $msg->send;
Can anyone see what I've done wrong in here, that it keeps sending the message as an attachement instead of as the email body?
Please note: the email addresses aren't listed correctly here. I starred them out since I'm testing on my own work email and want to leave as few instances of that out on the web to become spambait as possible. The actual addresses are valid.
I use Net::SMTP to send HTML email for a client, but you don't seem to, even though you 'use' it. Also, you don't seem to have a legal HTML document, but just a table. You need to wrap everything in HTML tags, as if it were a stand-alone HTML document.
Try a simple test of sending HTML email to yourself using something like this:
my $smtp = Net::SMTP->new('localhost');
$smtp->data();
my $msgformat = "text/html";
$smtp->datasend("Content-Type: $msgformat\n");
$smtp->datasend("To: $e\n");
$smtp->datasend("From: $From\n");
$smtp->datasend("Subject: $Subject\n\n");
$smtp->datasend("$HeaderHTML");
$smtp->datasend("$ContentHTML");
$smtp->datasend("$FooterHTML");
$smtp->dataend();
$smtp->quit();where you have defined the variables elsewhere.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
"Others make web sites. We make web sites work!"
![]() |
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Programming FAQ - Updated 1/March/2005 (Computer Science and Software Design)
- Perl question (Perl)
- I get the error no file or directory when i try to run a perl script (Perl)
- How to execute .exe file from the perl script (Perl)
- i get an error while trying to run perl on win98 (Perl)
- Posting Large amounts of text from Guestbook (Perl)
- perl for win98 were do i start (Perl)
- Safe Perl (Perl)
Other Threads in the Perl Forum
- Previous Thread: regular expression - details...
- Next Thread: code to activate submit button


Linear Mode