PHP: Sending Email with Cyrillic (Ukrainian text)

别来无恙 提交于 2019-12-02 16:38:18

问题


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

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

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);

Thank You,


回答1:


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.

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">

and see how it works.

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';

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



来源:https://stackoverflow.com/questions/47032977/php-sending-email-with-cyrillic-ukrainian-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!