PHP:使用西里尔字母发送电子邮件(乌克兰文字) [英] PHP: Sending Email with Cyrillic (Ukrainian text)

查看:218
本文介绍了PHP:使用西里尔字母发送电子邮件(乌克兰文字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PHP发送西里尔字母的问题. 我这边: 服务器IIS-数据库MsSQL-电子邮件服务器:Exchange 2010/通过PHP EWS通讯/

Problem with sending Cyrillic Email with PHP. My side: Server IIS - Database MsSQL - email server: Exchange 2010 /communication via PHP EWS/

Reciever是UA Goverment拥有的公司,其特定软件用于接收电子邮件.它正在使用MS Outlook/手动发送/.

Reciever is UA Goverment owned company with their specific software for receiving emails. It is working with MS Outlook /manually send/.

我尝试将其发送为文本/not html/,或者我尝试使用PHP Mailer,我也已经尝试过使用C#/所有在此特定公司/不在gmail或hotmail上都正常工作//.

I tried send it as text /not html/ or i tried PHP Mailer, i also already tried with C# /all are not working with this specific company /on gmail or hotmail it's working fine//.

$ews = new ExchangeWebServices($server, $username, $password);

$msg = new EWSType_MessageType();

$toAddresses = array();
$toAddresses[0] = new EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress =;
$toAddresses[0]->Name =; 

$msg->ToRecipients = $toAddresses;

$fromAddress = new EWSType_EmailAddressType();

$fromAddress->EmailAddress =;
$fromAddress->Name =;


$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;

$msg->Subject = "Test";

$msg->Body = new EWSType_BodyType();

$msg->Body->BodyType = 'HTML'; //Text HTML
$msg->Body->_ = $UAText;

$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;

$response = $ews->CreateItem($msgRequest);
var_dump($response);

谢谢

推荐答案

如果它与普通的Outlook客户端一起使用,但不适用于您的解决方案,那么我的第一笔检查就是比较两封示例电子邮件的标头(一个来自Outlook,另一个来自从您的解决方案中).我认为内容类型是使用Outlook正确设置的,但不是您的解决方案设置的.

If its working with an normal Outlook client, however not with your solution my first check would be to compare the header from two example emails (one from outlook and one from your solution). I think that the content-type is set correctly with Outlook however not with your solution.

因此,您可能希望在解决方案中将内容编码设置为UTF-8.因此,我假设$ UAText中的内容是一些HTML内容.因此,您可能希望通过以下方式将该部件标记为UTF-8:

So you might wish to set the content encoding to UTF-8 in your solution. So I assume the content inside $UAText is some HTML stuff. You might therefore wish to flag that part as UTF-8 via:

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

并查看其工作原理.

另外,您可能希望通过以下方式直接在代码内部设置编码:

Additional you might wish to set the encoding directly inside your code via:

$ews = new ExchangeWebServices($host, $user, $password, ExchangeWebServices::VERSION_2007_SP1);
$msg = new EWSType_MessageType();
$msg->MimeContent = new EWSType_MimeContentType();
$msg->MimeContent->_ = base64_encode("Mime-Version: 1.0\r\n"
    . "From: michael@contoso.com\r\n"
    . "To: amy@contoso.com\r\n"
    . "Subject: nothing\r\n"
    . "Date: Tue, 15 Feb 2011 22:06:21 -0000\r\n"
    . "Message-ID: <{0}>\r\n"
    . "X-Experimental: some value\r\n"
    . "\r\n"
    . "I have nothing further to say.\r\n");
$msg->MimeContent->CharacterSet = 'UTF-8';

注意:这是一个很好的关于内容类型的起点编码选项.您也可能希望查看官方的Microsoft howto

Note: Here is a good starting point regarding the content-type encoding option. You also might wish to check the official Microsoft howto here.

这篇关于PHP:使用西里尔字母发送电子邮件(乌克兰文字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆