2014-01-16 53 views
1

我試圖通過.asp(經典)頁面發送泰語電子郵件。代碼如下如何解決發送電子郵件泰語文字?

<% 
response.write(GetLocale() & "<br />") 
SetLocale(1054) 
response.write(GetLocale()) 


Set Mail = CreateObject("CDO.Message") 

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.gmail.com" 
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="[email protected]" 
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxx" 

Mail.Configuration.Fields.Update 

Mail.Subject="ระบบแจ้งเตือนอัตโนมัติ" 
Mail.From="[email protected]" 
Mail.To="[email protected]" 
Mail.TextBody="สวัสดี" 



Mail.Send 
Set Mail = Nothing 

%> 

但結果電子郵件我得到的是

????? ???????????????????? ?????????????????????????????????????????????????? ?????????????????????? ?????????????????????????????????????????????????? ??????

任何身體知道如何解決,請大家幫忙?

方法來解決是(由下面ulluoink)

鮮爲人知的位鄰善良添加到您的網頁:

Response.CodePage = 65001 
Response.CharSet = "utf-8" 

更改XML:

<?xml version="1.0" encoding="UTF-8" ?>. 

你也可以確保你的META標籤不說謊:

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

,並使用此代碼模式:

<% 
function TestEMail(sFrom, sTo, sSubject, sBody, sBcc) 
    Set objMail = Server.CreateObject("CDO.Message") 
    Set objConf = Server.CreateObject("CDO.Configuration") 
    Set objFields = objConf.Fields 
    With objFields 
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.secureserver.net" 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
     .Update 
    End With 

    With objMail 
     Set .Configuration = objConf 
     .BodyPart.Charset = "utf-8" 
     .From = sFrom 
     .To = sTo 
     .Subject = sSubject 
     .TextBody = sBody 
     if sBcc <> "" then .Bcc = sBcc 
     End With 

    objMail.Send 
    Set objFields = Nothing 
    Set objConf = Nothing 
    Set objMail = Nothing 
End function 
%> 

回答

1

你必須使用UTF-8編碼爲以下:

  • 你的ASP頁面(該文件必須保存在UTF-8編碼

    Response.CodePage = 65001

    :)
  • 然後使用設置在ASP的編碼

    Response.Charset的= 「UTF-8」

  • 集UTF-8在您的消息對象的身體部分:

    Mail.BodyPart.Charset = 「UTF-8」

此外看看here(hanselman關於經典的asp和utf-8)和here(cdo和utf-8的例子)

+0

非常好,問題解決了!非常感謝你。 – Jackth

相關問題