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

Discussion in 'Perl Misc' started by alamukutty@gmail.com, Dec 9, 2004.

  1. Guest

    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 =>'',

    To =>',
    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
     
    , Dec 9, 2004
    #1
    1. Advertising

  2. Re: Using MIME::Lite for multipart message - trouble with stringmanipulation

    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
     
    Gunnar Hjalmarsson, Dec 9, 2004
    #2
    1. Advertising

  3. Paul Lalli Guest

    <> wrote in message
    news:...

    > 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
     
    Paul Lalli, Dec 9, 2004
    #3
  4. AlamuKutty Guest

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

    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 !
     
    AlamuKutty, Dec 9, 2004
    #4
  5. Re: Using MIME::Lite for multipart message - trouble with stringmanipulation

    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
     
    Gunnar Hjalmarsson, Dec 9, 2004
    #5
  6. AlamuKutty Guest

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

    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!
     
    AlamuKutty, Dec 9, 2004
    #6
  7. Re: Using MIME::Lite for multipart message - trouble with stringmanipulation

    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
     
    Gunnar Hjalmarsson, Dec 9, 2004
    #7
  8. Tintin Guest

    <> wrote in message
    news:...
    > 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?
     
    Tintin, Dec 9, 2004
    #8
  9. AlamuKutty Guest

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

    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:...
    > > 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?
     
    AlamuKutty, Dec 10, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John B. Kim

    MIME::Lite HTML message handling

    John B. Kim, Jan 18, 2004, in forum: Perl
    Replies:
    1
    Views:
    1,727
    Joe Smith
    Jan 19, 2004
  2. Guoqi Zheng

    mime multipart message

    Guoqi Zheng, May 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    531
    Guoqi Zheng
    May 22, 2004
  3. Aaron Brady

    SQL, lite lite lite

    Aaron Brady, Dec 29, 2008, in forum: Python
    Replies:
    15
    Views:
    792
    Aaron Brady
    Jan 1, 2009
  4. Replies:
    1
    Views:
    466
  5. Ted Byers
    Replies:
    0
    Views:
    303
    Ted Byers
    Jun 24, 2010
Loading...

Share This Page