Question

I'm using CDO.Message to send emails from a contact form on an ASP Classic website to the site owner. The site is in Hebrew and I've encoded everything with UTF-8.

My problem is that in Outlook 2007 the Hebrew sent from the form comes out in gibberish. Other text in Hebrew in the email (ie. hardcoded text) displays correctly.

I've checked these emails in Outlook 2010 and online at Gmail and all the Hebrew looks fine.

Of course my client has Outlook 2007 and is not likely to change anytime soon.

Does anyone know how I can fix this?

Here is the script for sending the emails:

Const CdoReferenceTypeName = 1
Dim objCDO, objBP
Set objCDO = Server.CreateObject("CDO.Message")
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "aaaa@bbbbb.co.il"
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "123456"
objCDO.Configuration.Fields.Update

objCDO.MimeFormatted = True
objCDO.To = email_to        
objCDO.Bcc = email_bcc
objCDO.From = email_from        

objCDO.Subject = email_subject      

objCDO.HTMLBody = email_body
objCDO.HTMLBodyPart.charset = "utf-8"
objCDO.BodyPart.charset = "utf-8"                                   

objCDO.Send

The form is submitted via the jquery malsup form plugin thus :

$('#contact_form').submit(function() {
    if (myvalidator.isValid()) {
        $(this).ajaxSubmit(function() { 
            $('#form_holder').html('thanks'); 
        });
    }
    return false;
});

The form also has an attachment so is sent thusly:

<form action="inc_contact_send.asp" method="post" enctype="multipart/form-data" id="contact_form">
Était-ce utile?

La solution

Try moving the:

objCDO.BodyPart.charset = "utf-8" 

up a couple of lines so that it preceeds the assignment to HTMLBody. It may also be worth you examining the content of email_body whilst debugging to be sure it contains the HTML you expect it should.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top