3

I'm trying to send an email containing Arabic text, my problem is that when I add the Arabic text to the email, it changes it to random letters (to do with the character encoding of the email - which I can't change).

Is there a built in function or a custom function I can use to convert the Arabic to HTML Codes (ا) so it will then appear in my HTML email?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Dan Ellis
  • 5,537
  • 8
  • 47
  • 73
  • Try the accepted answer in this question: http://stackoverflow.com/questions/2386843/cdosys-and-unicode-in-the-from-field-vbscript – Shadow The GPT Wizard May 25 '11 at 13:11
  • What method are you using to send your e-mail? – C. Ross May 25 '11 at 13:48
  • I'm using ASPMail, version 4. I'm also using the CustomCharSet parameter but it seems to not have any effect on the email. When I view the email in Outlook, it sets it to the default charset. If I change it using outlook, all the Arabic text displays fine. – Dan Ellis May 25 '11 at 14:06

2 Answers2

2

Have you tried setting the encoding type in the HTML header?

Add the following to the <head> section of your HTML:

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

This should make your arabic (and other non-ascii) characters render properly.

That said, it's important to note that when sending HTML emails, you will always have an issue because different email clients in common use have wildly different capabilities -- even more so than browsers.

One person may open the email in a current version of Outlook, another in a ten-year-old copy. Someone else may use some version of Thunderbird, and many others will use a webmail client like Hotmail, Yahoo, Gmail, or countless others. There may even be people who still have their email set to show text mode emails rather than HTML.

You probably have no control over any of that, so its important to be sure you've tested in a variety of email clients. That said, given that you're sending Arabic text, it can be assumed that most of your recipients will be using an email client that can render Arabic successfully, so hopefully that fact alone should mitigate the worst of this issue for you.

Spudley
  • 166,037
  • 39
  • 233
  • 307
1

Leave the HTML escapes (ex &#1505;) in, and turn the e-mail to HTML by setting ContentType to text/html

'Create mailer
mailer.ContentType = "text/html"
'User mailer

To convert the unicode to HTML escapes you can use the built in function HTMLEncode.

mailer.BodyText =  Server.HTMLEncode(body)

Note: Your viewer will need to have the appropriate set of glyphs installed.

C. Ross
  • 31,137
  • 42
  • 147
  • 238
  • Just tried changing it to HTML (ASPMail doesn't seem to have an IsHTML property so I had to change the content type), although my problem is that some of the text is "HTML escapes" and other bits of text is plain Arabic text so I need to convert the plain Arabic text to "HTML escapes" so that it displays in the email. If I diplay the plain Arabic text in the email, it just displays random letters, not Arabic. – Dan Ellis May 25 '11 at 16:27
  • Server.HtmlEncode does convert them to the HTML escape characters, but when I receive my email, the characters appear as: ÊâÏêå ÇäÇÓå: ÊÍÊÇÌ Åáì ÇáãÒíÏ rather than Arabic. Although I am setting the charset of the email to ISO-8859-6 it still things it's UTF-8 or something. – Dan Ellis May 25 '11 at 19:31
  • @Scrooby sounds like a setting somewhere on your mailer object, have you checked the headers on your mail in Outlook? ... – C. Ross May 25 '11 at 19:33
  • It's very strange. It was to do with my email charset. It seemed that whenever I set the email to HTML, it would totally disregard my custom charset. So I tried various things to try and get the charset in there, in the end nothing worked so I reverted back, and now it works :S Can't explain it. Thanks for all your help and advice though, been a great help :) – Dan Ellis May 25 '11 at 20:29