Hi, I am using this sendmail.cgi perl script below to receive by email online form data but it is not able to properly encode some foreign characters.

For example this string

Plaça de la Germandat 7 Sant Julià de Lòra

is converted to

Plaça de la Germandat 7 Sant Julià de Lòra

when received as plain text email and read in Outlook. I have already added

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

in the html form heading and

AddDefaultCharset UTF-8

in the .htaccess file but they do not seem to make any difference.

What should I add to the script to receive the correct utf-8 characters? Or is there any other solution? Thanks for any help.

#!/usr/bin/perl sub sdsmail { $MAIL_sort_lines = ""; if ($formdata{'sort'}) { @sortfields = split(/,/,$formdata{'sort'}); for ($numsort = 0; $numsort < @sortfields; $numsort++) { $sort_field = $sortfields[$numsort]; $sort_value = $formdata{"$sort_field"}; if ($PRNT_blankfields eq "2" && ! $sort_value) {}else{ $MAIL_sort_lines = "$MAIL_sort_lines$sort_field : $sort_value +\n\n"; } ## END CHECK PRINT BLANK FIELDS ## } } ## END ELSE IF SORT FIELD ## $MAIL_all_lines = "The form below was submited by $POSTER_email form I +p address: $ENV{'REMOTE_ADDR'} on $D_month $L_day, $year at $L_hour:$ +L_min $nightday \n"; $MAIL_all_lines = "$MAIL_all_lines ----------------------------------- +--------------------------------------\n\n"; if ($formdata{'sort'}) { $MAIL_all_lines = "$MAIL_all_lines$MAIL_sort_lines"; }else{ $MAIL_all_lines = "$MAIL_all_lines$MAIL_filed_lines"; } ## INJECTION PREVETION ## $MAIL_all_lines =~ s/\r\n/\n/g; $MAIL_all_lines =~ s/\r//g; $MAIL_all_lines =~ s/To:/To;/g; $MAIL_all_lines =~ s/Cc:/Cc;/g; $MAIL_all_lines =~ s/From:/From;/g; $MAIL_all_lines =~ s/Subject:/Subject;/g; ## END INJECTION PREVETION ## if ($send_email_results eq "1") { ## START SEND CUSTOM EMAIL ## if ($SEND_custom_result eq "1") { if ($formdata{'custom_message_format'} eq "html"){ if ($formdata{'custom_mesfile'}) { $FORM_custom_mes = "$formdata{'html_custom_mesfile'}"; $CUSTOM_MESSAGE_fl = $CUSTOM_mes_html{"$FORM_custom_me +s"}; }else{ $CUSTOM_MESSAGE_fl = $CUSTOM_mes_html{"1"}; } }else{ if ($formdata{'custom_mesfile'}) { $FORM_custom_mes = "$formdata{'plain_custom_mesfile'}" +; $CUSTOM_MESSAGE_fl = $CUSTOM_mes_plain{"$FORM_custom_m +es"}; }else{ $CUSTOM_MESSAGE_fl = $CUSTOM_mes_plain{"1"}; } } require "$ABSOLUTE_PATH_TO_CGI_BIN$CGI_custom_email"; &send_custom_email; ##$MAIL_all_lines = "The form below was submited by $POSTER_em +ail form Ip address: $ENV{'REMOTE_ADDR'} on $D_month $L_day, $year at + $L_hour:$L_min $nightday \n"; ##$MAIL_all_lines = "$MAIL_all_lines ------------------------- +------------------------------------------------\n\n"; $MAIL_all_lines = "\n"; $MAIL_all_lines = $MAIL_all_lines."$CUSTOM_body\n\n"; $MAIL_all_lines =~ s/\r\n/\n/g; $MAIL_all_lines =~ s/\r//g; $MAIL_all_lines =~ s/To:/To;/g; $MAIL_all_lines =~ s/Cc:/Cc;/g; $MAIL_all_lines =~ s/From:/From;/g; $MAIL_all_lines =~ s/Subject:/Subject;/g; ##print "Content-type: text/html\n\n"; ##print "<BR><BR>$MAIL_all_lines<br><br>"; ##exit; } ## END SEND CUSTOM EMAIL ## ## VERIFY CC TO, AND THEN SEND RESULTS... ## @ALL_SENDTO = ("$mail_sendto"); if ($mail_ccto) { push (@ALL_SENDTO, $mail_ccto); } if ($formdata{'bcc_to'}) { @BCC_NUMB = split(/,/,$formdata{'bcc_to'}); foreach $bcc_ad (@BCC_NUMB) { push (@ALL_SENDTO, $cc_to{"$bcc_ad"}); } } if ($USE_MIME eq "1") { if ($send_from_poster eq "1") { $MAIL_r_from = "$formdata{'email'}"; }else{ $MAIL_r_from = "$FROM_results_email"; } foreach $SEND_email_to (@ALL_SENDTO) { use MIME::Lite; MIME::Lite->send("sendmail", "$mailprog -t -oi -oem"); $msg = MIME::Lite->new(From => $MAIL_r_from, To => $SEND_e +mail_to, Subject => $formdata{'subject'}, Type => $email_format, Data + => $MAIL_all_lines); $msg->send; } ## END FOR EACH ## }else{ ## ELSE SEND PLAIN TEXT ## foreach $SEND_email_to (@ALL_SENDTO) { ## S T A R T M A I L H E A D E R S ## $MAIL_headers = "To: $SEND_email_to\n"; if ($send_from_poster eq "1") { $MAIL_headers = $MAIL_headers."From: $formdata{'email' +}\n"; }else{ $MAIL_headers = $MAIL_headers."From: $FROM_results_ema +il\n"; } $MAIL_headers = $MAIL_headers."Subject: $formdata{'sub +ject'}\n"; $PREDEFINED_mail_contents = "$MAIL_headers$MAIL_all_lines\ +n\n"; open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\ +n"; print MAIL "$PREDEFINED_mail_contents\n\n"; close MAIL; } ## END FOR EACH ## } ## END SEND THROUGH MIME ## ## IF SEND RESULTS TO CELL PHONE... ## if ($formdata{'cell_to'}) { $CELL_sendto = $sendto{"$formdata{'cell_to'}"}; if ($formdata{'cell_mesfile'}) { $CUSTOM_MESSAGE_fl = $CELL_mesfile{"$formdata{'cell_mesfil +e'}"}; }else{ $CUSTOM_MESSAGE_fl = $CELL_mesfile{"1"}; } if ($SEND_custom_result != "1") { require "$ABSOLUTE_PATH_TO_CGI_BIN$CGI_custom_email"; } &send_custom_email; ## S T A R T M A I L H E A D E R S ## $MAIL_headers = "To: $CELL_sendto\n"; if ($send_from_poster eq "1") { $MAIL_headers = $MAIL_headers."From: $formdata{'email' +}\n"; }else{ $MAIL_headers = $MAIL_headers."From: $FROM_results_ema +il\n"; } $MAIL_headers = $MAIL_headers."Subject: $formdata{'sub +ject'}\n"; $PREDEFINED_mail_contents = "$MAIL_headers\n$CUSTOM_body\n +\n"; open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\ +n"; print MAIL "$PREDEFINED_mail_contents\n\n"; close MAIL; } ## END IF SEND RESULTS TO CELL PHONE... ## } ## END IF SEND_EMAIL_RESULTS## if ($formdata{'sendreply'} eq "1"){ if ($USE_MIME eq "1") { use MIME::Lite; MIME::Lite->send("sendmail", "$mailprog -t -oi -oem"); $msg = MIME::Lite->new( From => $mail_sendto, To => $POSTER_email, Subject => $reply_subject, Type => $email_format, Data => $mime_body); ## if ($send_attachment eq "1"){ ## if ($formdata{'file_attachments'}){ @fe_attachments = split(/,/,$formdata{'file_attachments'}) +; foreach $attach_numb (@fe_attachments) { $attachment_nm = $ATTACHMENT_file{"$attach_numb"}; @ATTACH_atrb = split(/,/,$ATTACHMENT_attributes{"$atta +ch_numb"}); $att_path = $ATTACHMENT_path{"$ATTACH_atrb[0]"}; $att_content_type = $ATTACHMENT_type{"$ATTACH_atrb[1]" +}; $GET_ext = "$attachment_nm"; $GET_ext =~ s/,//g; $GET_ext =~ s/\./,/g; @ATTACH_format = split(/,/,$GET_ext); $att_format = ""; foreach $ATTACH_fm (@ATTACH_format) { if ($ATTACH_fm) { $att_format = ".$ATTACH_fm"; } } $att_path = "$att_path$attachment_nm"; $msg->attach(Type => $att_content_type, Encoding => $att_f +ormat->[1], Path => $att_path, Filename => $attachment_nm); } } ## END SEND ATTACHMENTS... ## $msg->send; }else{ ## SEND AUTO REPLY PLAIN TEXT ## $REPLY_MAIL_headers = "To: $POSTER_email\n"; $REPLY_MAIL_headers = $REPLY_MAIL_headers."From: $mail_sendto\ +n"; $REPLY_MAIL_headers = $REPLY_MAIL_headers."Subject: $reply_sub +ject\n"; open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n"; print MAIL "$REPLY_MAIL_headers\n$mime_body\n\n"; close MAIL; } }}return 1;

In reply to sendmail.cgi and utf-8 encoding issue with foreign characters by world33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.