Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: UTF-8 Email Form

by Polyglot (Friar)
on Mar 18, 2018 at 16:10 UTC ( #1211191=note: print w/replies, xml ) Need Help??

in reply to UTF-8 Email Form

The ubiquitous "sendmail" handles UTF8 just fine. A very simple subroutine I have used to handle a specific form in Thai is presented below. (NOTE: It appears that converts all UTF8 characters to HTML-entitites, even in <code></code> blocks, which is not the way I used it, so I have had to format my code in HTML style for proper readability.)


sub emailFormResults {
# Email the form results
open ( MAIL, "| /usr/lib/sendmail -t" );
#open ( MAIL, "| /usr/lib/sendmail", "-oi", "-t");
print MAIL "From: $sending_email_address\n";
print MAIL "To: $recipient_address\n";
print MAIL "BCC: $bcc_address\n";
print MAIL "Subject: $message_subject\n\n";
1. Personal Information / ข้อมูลส่วนตัว
* National ID / หมายเลขประจำตัว(ตามบัตรประจำตัวประชาชน): $national_id
* Title (นาย/นางสาว/นาง/ยศ): $title
* Full Name / ชื่อ-สกุล: $fullname
* Maiden Name / ชื่อ-สกุลเดิม(ถ้ามี): $maiden_name
* Birthday / วดป.เกิด: $birthday
* Current Address / ที่อยู่ปัจจุบัน บ้านเลขที่: $current_address
* Home Phone / หมายเลขโทรศัพท์บ้าน: $home_phone
* Cell Phone / มือถือ: $cell_phone
* Email: $email_address
* LINE Id: $line_id
* Facebook: $facebook
2. Occupational Information / ข้อมูลการประกอบอาชีพ ปัจจุบันประกอบอาชีพ: $occupation
* Position / ตำแหน่ง: $position
* Company / ชื่อ สถานที่ทำงาน: $company
* Salary / รายได้ต่อเดือน: $salary บาท
ฝากข้อความ: $comments
print MAIL "\n.\n";
close ( MAIL );
} # END SUB emailFormResults

Note that the form itself should be set to accept only UTF-8, and the HTML for the page should be properly set as well. I have used the following pieces successfully.

print <<HTML;
<html lang="th">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
. . .
<form name="myform" id="myform" action="$0" method="post" accept-charset="UTF-8">



Replies are listed 'Best First'.
Re^2: UTF-8 Email Form
by Your Mother (Archbishop) on Mar 18, 2018 at 18:28 UTC

    I don't use sendmail directly like this but I'm pretty sure it will fail on the Header fields (To, Cc, Subject, etc) when they contain extra-ASCII. For that you can use Encode/Encode::MIME::Header.

    use Encode; my $subject = encode("MIME-Header", $some_utf8_string);

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1211191]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2021-09-24 13:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found