E-mail UTF-8 via ASP with CDONT

Asked

Viewed 785 times

5

I am trying to send a form to an email using CDONT, but the charset is coming incorrectly and is not showing the accented characters correctly.

<%
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"
mail_to = "[email protected]"

Dim f, emsg, mail_to, r, o, c, other
emsg =  "<!DOCTYPE html><html lang=""pt-br""><head><meta charset=""UTF-8"" /></head><body>" & _
        "<strong>Solicitante: " & Request("txtSol") & vbCrLF & _
        "Data da solicitação:</strong> " & Request("txDatatSol") & vbCrLF  & _
        "Setor: " & Request("cboSetor") & vbCrLF & _
        "Descrição do produto/serviço: "  & vbCrLF & Request("txtProdServ") & vbCrLF & _
        "Justificativa da solicitação: "  & vbCrLF & Request("txtJust") & vbCrLF & _
        "Valor médio: " & Request("txValor") & vbCrLF & _
        "Prazo limite: " & Request("txDatatLim") & vbCrLF & _
        "Especificações técnicas do produto/serviço e requisitos da qualidade exigidos: "  & vbCrLF & Request("txtEspcTec") & vbCrLF & _
        "Produto Crítico? " & Request("rdoCritico") & vbCrLF & _
        "Possíveis fornecedores: " & vbCrLF & Request("txtFornc")  & vbCrLF & _
        "Fornecedor exclusivo? " & Request("rdoExclusivo") & vbCrLF & _
        "Você confirma o envio do parecer técnico? " & Request("rdoParecer") & _
        "</body> </html>"

For Each f In Request.Form
    If mid(f,1,1)<>"S"  = True Then
        emsg = emsg & f & " = " & Trim(Request.Form(f))
    End If
Next

Set objNewMail = Server.CreateObject("CDONTS.NewMail")
    objNewMail.From = Request("txtSol")
    objNewMail.Subject = "Solicitação de compra"
    objNewMail.To = mail_to
    objNewMail.BodyFormat=0
    objNewMail.MailFormat=0
    objNewMail.Body = emsg 
    objNewMail.Send
    Set objNewMail = Nothing

response.redirect "home.asp?status=enviado"

%>
  • Is the source file encoded in UTF-8? You can check by opening it in Notepad++ and going to Format. Even, you can convert to UTF-8. As your email is getting data from another page, make sure there is also in UTF-8. And send the Form using POST.

  • Yes, the files are in UTF-8. I’ve tested so much through the POST how much GET.

2 answers

3

Working with UTF-8 is not enough Response.CodePage and the Response.Charset, it is necessary to save both documents in UTF-8 NO GOOD, both the upload file and the file containing the form.

Two softwares that can be used to save the document with the required encoding are the Notepad++ or Sublimetext:

Using Notepad++:

utf8 sem boom notepad++

Using Sublime Text:

utf8 sublime sublimetext

If you are sure that both files are saved like this, then it is necessary to apply Response.CodePage and Response.Charset in both documents.

If you have already done all these procedures and the sending of the e-mail still has problems in the characters, then you will need to use one of these properties, as the colleague mentioned in the other reply:

objNewMail.BodyPart.Charset = "utf-8"

or

objNewMail.HTMLBodyPart.Charset = "utf-8"

A detail, I don’t have much knowledge of classic Asp, but I believe that the mail_to = "[email protected]" should go after Dim:

Dim f, emsg, mail_to, r, o, c, other

mail_to = "[email protected]"
emsg =  "<!DOCTYPE html>...

0

To send emails with the correct UTF-8 encoding, use:

bjCDOMailer.TextBodyPart.Charset = "utf-8"

For the encoding to work properly:

objCDOMailer.BodyPart.Charset = "utf-8" 
objCDOMailer.HTMLBodyPart.Charset = "utf-8"
  • So it works only with CDO.Message.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.