Results 1 to 4 of 4
  1. #1
    Full Member c4's Avatar
    Join Date
    January 18th, 2005
    Posts
    488
    Hi!

    I have a (pretty basic I guess) CGI question - I wrote a script which sends an e-mail with the data which some user entered in a HTML form. Now the problem is that when I receive the e-mail it looks like this:

    The headers (to, from, subject) are ok, but the message is screwed: If I enter "This is a test text" in the form I get the same message in mail but with "+" between words ( "This+is+a+test+text" ).

    What trick should I use to prevent those "+" to be included in the mail?

    Here's the code I wrote:


    #!/usr/bin/perl
    $admin_mail = "myemail\@email.si";
    $mailprog = "/usr/sbin/sendmail -t";
    $site_name = "Azimnica";
    $site_url = "http://wwwsquad.thetaworld.net/";

    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $name =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;}

    if ($FORM{'name'} eq "") {&error;}
    elsif ($FORM{'email'} eq "") {&error;}
    elsif ($FORM{'subject'} eq "") {&error;}
    elsif ($FORM{'message'} eq "") {&error;}
    else{
    $name = $FORM{'name'};
    $email = $FORM{'email'};
    $subject = $FORM{'subject'};
    $message = $FORM{'message'};

    open(MAIL,"|$mailprog");
    print MAIL "To: $admin_mail\n";
    print MAIL "Subject: $subject\n";
    print MAIL "Message from: \n\n";
    print MAIL "$name\n";
    print MAIL "$email\n\n";
    print MAIL "His message: \n\n";
    print MAIL "$message\n\n\n";
    print MAIL "Webmaster ( mailto:$admin_mail )\n";
    print MAIL "$site_url\n";
    close(MAIL);

    &thanks;
    }

    **************
    ... and 2 subroutines which don't really matter now (just "Thank you" and "Error" messages).

    Thanks in advance!

  2. #2
    ABW Veteran Student Heyder's Avatar
    Join Date
    January 18th, 2005
    Posts
    5,482
    Not an expert but I think you need to put an if statement for the spaces.

  3. #3
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    String Substitution
    source:HERE
    Given our variable $sentence = "I went to the shop"; we can change shop to movies like this

    $sentence =~ s/shop/movies/;

    so, in this situation:
    $sentence =~ s/+/ /;

    [edit] you might need to try $sentence =~ s/\+/\ /;

    I haven't tested it, but try it... it might work.

    [ 03-26-2002: Message edited by: Pete ]

  4. #4
    Full Member c4's Avatar
    Join Date
    January 18th, 2005
    Posts
    488
    Thanks Pete, I got it working [img]/infopop/emoticons/icon_smile.gif[/img] You helped me many times with CGI, nice to have people like you [img]/infopop/emoticons/icon_smile.gif[/img]

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Array of Html Forms on Same Page?
    By Uncle Rico in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: August 6th, 2009, 12:57 AM
  2. cgi-email forms + success page
    By Cursal in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: November 2nd, 2004, 09:24 AM
  3. HTML Forms
    By gregdi in forum Programming / Datafeeds / Tools
    Replies: 4
    Last Post: April 5th, 2004, 07:06 AM
  4. SEs and PHP,pl, CGI, and HTML
    By Doug247 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: October 8th, 2003, 09:17 PM
  5. Sending out HTML email to highlight your merchant partners?
    By BareNecessities in forum Voting Booth
    Replies: 0
    Last Post: October 29th, 2002, 09:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •