Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Using MIME::Lite for multipart message - trouble with string manipulation

Reply
Thread Tools

Using MIME::Lite for multipart message - trouble with string manipulation

 
 
alamukutty@gmail.com
Guest
Posts: n/a
 
      12-09-2004
Hi,

I am pretty new to cgi-perl and I'm trying to process a form and
send the email using sendmail. I figured how to send attachments using
MIME::Lite and also figured how to process a form and send a plain
text mail like

for each param()
ParamName = Param vAlue

When I try to put the two together, I am stuck. I don't know how to
process strings with perl and any help will be appreciated.
For now, this is what I am trying and I get a server error.

----------------------

#! / usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use lib '/usr/lib/perl5/site_perl/5.8.0/MIME';
use MIME::Lite;

print start_html("Thank You");

# Set the PATH environment variable to the same path
# where sendmail is located:

$ENV{PATH} = "/usr/sbin";

# Now print the body of your mail message.

my $body_string;

foreach my $p (param()) {

$body_string = print "$p = ", param($p), "\n";

}

my $msg = MIME::Lite->new(

>From =>'webmas...@myhost.org',

To =>m...@myhost.org',
Subject =>'Form Data!',
Type =>'multipart/mixed',
);
$msg->attach(
Type => 'TEXT',

Data => $body_string );

$msg->attach(
Type =>'application/msword',
Path => '/usr/local/apache2/htdocs/checking.doc'

);

$msg->send();

# Be sure to close the MAIL input stream so that the
# message actually gets mailed.

# Now print a thank-you page

print <<EndHTML;

<h2>Thank You</h2>

<p>Your information has been submitted.</p>

<p>Return to our <a href="index.htm">home page</a>.</p>
EndHTML

print end_html;

----------

Thanks in advance.

AK

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-09-2004
wrote:
> ... I get a server error.


<snip>

You need to print a content-type header and tell the server that you
start printing the actual page before printing other stuff to STDOUT.

print header();

> print start_html("Thank You");


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      12-09-2004
<> wrote in message
news: oups.com...

> foreach my $p (param()) {
> $body_string = print "$p = ", param($p), "\n";
> }


What exactly do you believe this is doing? I sincerely doubt that it's
doing it.

Paul Lalli

 
Reply With Quote
 
AlamuKutty
Guest
Posts: n/a
 
      12-09-2004
I figured that wasnt doing what I wanted to do. I changed that part of
the code to

my $body_string = "" ;

foreach my $p (param()) {
$body_string .= sprintf("%s = %s\n", $p, param($p));
}


Now, I have another question.

Is there anyway to format this text to be HTML ? So that I get a nice
format in my e-mail

param name(inbold) = Param value
<double spacing here>

..... repeated?


Thanks !

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-09-2004
AlamuKutty wrote:
>
> foreach my $p (param()) {
> $body_string .= sprintf("%s = %s\n", $p, param($p));
> }
>
> Now, I have another question.
>
> Is there anyway to format this text to be HTML ? So that I get a nice
> format in my e-mail


HTML is not a nice format in any email message.

> param name(inbold) = Param value
> <double spacing here>
>
> .... repeated?


You just print the appropriate HTML stuff in addition to what you
already have... What's the reason why you ask?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
AlamuKutty
Guest
Posts: n/a
 
      12-09-2004
Hi GUnnar, I'll try that. NOw... ANOTHEr question..

Having trouble with this part ..

$file_attached = param('fileattach');
$msg->attach(
Type =>'application/msword',
Path => $file_attached

);

It says file not found. I am guessing it looks in the webserver and not
in the local machine? And the PATH to the file selected is not
displayed. For instance,if I select a file "Testing.doc" from
C:/Desktop/blahblah/TEsting.doc It doesnt work ... what should i be
doing? THANKS!

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-09-2004
AlamuKutty wrote:
> Having trouble with this part ..
>
> $file_attached = param('fileattach');
> $msg->attach(
> Type =>'application/msword',
> Path => $file_attached
>
> );
>
> It says file not found. I am guessing it looks in the webserver and not
> in the local machine?


That sounds plausible.

I would suggest that you split the problem in two parts.

1) You need to learn how to upload a file to the server machine.

2) You need to know how to send an email message with an attachment.

I'd suggest that you write two separate scripts to handle those things.
Only after you have done so successfully, it's time to combine them.

As regards uploading a file, please study the CGI.pm docs about it. Note
also that the form needs

enctype="multipart/form-data"

in the <form> element.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      12-09-2004

<> wrote in message
news: oups.com...
> Hi,
>
> I am pretty new to cgi-perl and I'm trying to process a form and
> send the email using sendmail. I figured how to send attachments using
> MIME::Lite and also figured how to process a form and send a plain
> text mail like
>
> for each param()
> ParamName = Param vAlue
>
> When I try to put the two together, I am stuck. I don't know how to
> process strings with perl and any help will be appreciated.
> For now, this is what I am trying and I get a server error.
>
> ----------------------
>
> #! / usr/bin/perl -w


That's a might strange path to perl on your system.

> use lib '/usr/lib/perl5/site_perl/5.8.0/MIME';


Why? Do you have different versions of perl installed?



 
Reply With Quote
 
AlamuKutty
Guest
Posts: n/a
 
      12-10-2004
I got it to work with MIME::Lite and CGI.pm . Thanks to everyone for
their patience and help!


Tintin wrote:
> <> wrote in message
> news: oups.com...
> > Hi,
> >
> > I am pretty new to cgi-perl and I'm trying to process a form and
> > send the email using sendmail. I figured how to send attachments

using
> > MIME::Lite and also figured how to process a form and send a plain
> > text mail like
> >
> > for each param()
> > ParamName = Param vAlue
> >
> > When I try to put the two together, I am stuck. I don't know how to
> > process strings with perl and any help will be appreciated.
> > For now, this is what I am trying and I get a server error.
> >
> > ----------------------
> >
> > #! / usr/bin/perl -w

>
> That's a might strange path to perl on your system.
>
> > use lib '/usr/lib/perl5/site_perl/5.8.0/MIME';

>
> Why? Do you have different versions of perl installed?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to read header of a multipart message using javaMail GunjanM Software 0 03-20-2008 08:37 PM
winhttprequest posting byte() and string in multipart message. Howto fnoppie@gmail.com ASP General 6 06-11-2007 08:38 PM
MIME Structure Multipart/Mixed with attachment and Multipart/Alternative blaine@worldweb.com Perl Misc 1 04-04-2007 08:23 PM
Trouble with ContentType multipart/form-data scottf35@gmail.com ASP .Net 0 12-01-2006 04:51 AM
mime multipart message Guoqi Zheng ASP .Net 0 05-22-2004 08:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57