I am using SMPP Receiver API to get the messages from specific MSISDN. I am getting the English text correctly. But the Dari and Pashto text is not in same format. It shows output like below :
/ '2(� /'HFD/1
My Code is :
ob_start();
require_once "smpp.php";//SMPP protocol
//connect to the smpp server
$tx=new SMPP('IP',PORT);
//bind the receiver
$tx->system_type="NUll";
$tx->addr_npi=0;
$tx->bindReceiver("username","password");
do
{
//read incoming sms
if($sms=$tx->readSMS())
{
print_r($sms);
}
}while($sms);
And smpp.php is at :
http://121.100.50.58/apps/smpp/
How I can get the correct Dari and Pashto Language Message text?
Try this
$utf8 = $body;
$encodedMessage = mb_convert_encoding($utf8, "UCS-2", "utf8");
$from = new SmppAddress($sender, SMPP::TON_ALPHANUMERIC);
$to = new SmppAddress($number, SMPP::TON_INTERNATIONAL, SMPP::NPI_E164);
$smppClient->sendSMS($from, $to, $encodedMessage, [], SMPP::DATA_CODING_UCS2);
It works completly for polish characters and I'm pretty sure it works with all unicode.
Save the .php script itself in utf-8. This also has to line up with the charset in your browser.
If that still doesnt work, check out mb_convert_encoding http://de2.php.net/manual/en/function.mb-convert-encoding.php.
The text seems to be sent from the SMSC in UNICODE. It should be just a matter of using the correct encoding and charset ... try using charset UTF16-BE and encoding UCS2
Related
Hi am using php smpp sms sending package to work on socket sms sending.
$transport = new SocketTransport(array(config('app.smppHost')), config('app.smppPort'));
$transport->setRecvTimeout(10000);
$smpp = new SmppClient($transport);
I am sending with $encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
$smpp->sendSMS($from,$to,$encodedMessage,null,null);
UPDATE
But the sms is receiving with broken character.I am sending in myn language and also tried as suggested
$smpp->sendSMS($from,$to,$encodedMessage,null,null);
But now half broken half proper message is sending. I think some encoded needed ???
This is special language encoded issue you need both override the encoded version in smpp package as well as encode the text itself.
First convert the string
mb_convert_encoding($message,'UCS-2',"utf8");
Then send sms in encoded in type 8. it should work properly
$smpp->sendSMS($from,$to,$encodedMessage,null,8);
My PHP app processes incoming emails. The processing code usually works fine, but the app crashed recently with the below exception:
Unexpected encoding - UTF-8 or ASCII was expected (View: /home/customer/www/gonativeguide.com/gng2-core/vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/panel.blade.php) {"exception":"[object] (Facade\\Ignition\\Exceptions\\ViewException(code: 0): Unexpected encoding - UTF-8 or ASCII was expected (View: /home/customer/www/gonativeguide.com/gng2-core/vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/panel.blade.php) at /home/customer/www/gonativeguide.com/gng2-core/vendor/league/commonmark/src/Input/MarkdownInput.php:30)
It seems that there was an incoming email whose text was not properly decoded and this made the app crash later on.
I realized that the email had a Windows-1252 encoding:
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
The email decoding code looks currently like this:
// DECODE DATA
$data = ($partno)?
imap_fetchbody($mbox,$mid,$partno): // multipart
imap_body($mbox,$mid); // simple
// Any part may be encoded, even plain text messages, so check everything.
if ($p->encoding==4)
$data = quoted_printable_decode($data);
elseif ($p->encoding==3)
$data = base64_decode($data);
I checked this page to understand what I need to change to decode emails with Windows-1252, but it not clear to me which value corresponds to Windows-1252 and how to decode and convert the data to UTF-8. I would highly appreciate any hints, preferably with suggested code on this.
Thanks,
W.
In your case, this line:
$data = quoted_printable_decode($data);
needs to be adapted like this:
$data = mb_convert_encoding(quoted_printable_decode($data), 'UTF-8', 'Windows-1252');
More generally, to cope with non-UTF-8 encodings, you may want to extract the charset of the body part:
from the body part structure, returned by imap_bodystruct(), or
from the body part MIME headers, returned by imap_fetchmime().
I'm wondering how to get the charset via PHP IMAP when imap_fetchmime() isn't supported. I either have a lower version of PHP that doesn't support it or maybe it's deprecated, but it doesn't work for me.
What I basically need is to find out the charset of the email via IMAP, so the output would be:
ISO-8859-1
Or whatever it turns out to be. I don't want to read the whole email to find out, I want to find out what the charset is so I can use the correct encoding.
Here is the code I'm using simplified down for the purpose of this email:
$mailbox = "xxx#gmail.com";
$mailboxPassword = "xxx";
$mailbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX",
mailbox, $mailboxPassword);
mb_internal_encoding("UTF-8");
$subject = mb_decode_mimeheader(str_replace('_', ' ', $subject));
$body = imap_fetchbody($mailbox, $val, 1);
$body = base64_decode($body);
echo $body;
I am trying to send Danish characters (Æ, Ø, Å) in an alarm notification using Easy APNs but when doing so, no message is send. If I send it with sound, only the sound is send. Also the message will be set to "null" in the database if it includes any of the Danish characters.
Does anyone know a fix for this?
This was caused by json_encode(). Using utf8_encode() on my alert views before json_encode() solved the issue.
UPDATE (How to fix the issue)
1. In class_APNS.php around line 411, you have
$msg = chr(0).pack("n",32).pack('H*',$token).pack("n",strlen($message)).$message;
Above that, put:
$message = utf8_encode($message);
2. In class_APNS.php (same file) put this:
$usermessage['aps']['alert'] = utf8_encode($usermessage['aps']['alert']);
Put it just above the following:
$fk_device = $this->db->prepare($list[$i]);
$message = $this->_jsonEncode($usermessage);
$message = $this->db->prepare($message);
$delivery = (!empty($when)) ? "'{$when}'":'NOW()';
I've set up a script that processes incoming emails and creates blog entries on Blogger. I'm using PEAR's Mail_Mime libs (for now) to read the incoming message. The messages often have characters in them that cannot be read by browsers--this happens most often when people use Outlook or cut/paste from MS Word.
So the output at the other end is something like this:
Here is a test post with “quotes” and ‘apostrophes�for what it�s worth, it also has dashes�and other strange formatting cut and paste from MS Word.
You can also see the output in the wild.
It's not hard to fix any specific instance, but each client (hotmail, gmail, outlook, etc) seems to handle things just a bit differently. Mail_Mime only seems to munge the output and, if I turn off Mail_Mime's parsing and try to translate the encoded characters myself using mb_convert_encoding or some manual simulation of this, it's even worse.
Please not that this is not going to be solved by selecting the right encoding type and using decode/encode/convert functions. The incoming formats vary from Windows-1252 to UTF8 to just about anything else mail clients can think of.
Has anyone scripted this before that could save me some time by offering up a sample or advice on the best approach? I've tried all the simple answers and done plenty of experimenting, so please don't bother responding unless you've dealt with a similar issue successfully or have a deep understanding of encoding issues.
The only way to do this is to do it by the spec's which is I'm afraid to pull in the 'Content-Type' mime header, pick up the charset (it'll look like Content-Type: text/plain; charset="us-ascii") then convert to UTF-8, and of course ensure your output on the web is sent as UTF-8 with the right headers.
To solve this problem, and get my message into valid UTF-8 that is readable from a browser, I found this PHP lib, ConvertCharset by Mikolaj Jedrzejak, which worked on almost everything. It still had issues with a specific symbol (=A0) when converting from Windows-1252 or iso-8859-1. So I converted this character manually before setting the code loose.
Here's what it looks like overall:
// decode using Mail_Mime
require 'Mail.php';
require 'Mail/mime.php';
require 'Mail/mimeDecode.php';
$params['include_bodies'] = true;
$params['decode_bodies'] = true; // this decodes it!
$params['decode_headers'] = true;
$decoder = new Mail_mimeDecode($input);
$mime = $decoder->decode($params);
// too much work to put in this example
$charset = ...; //do some magic with $mime->parts to get the character set
$text = ...; //do some magic with $mime->parts to get the text
// fix the =A0 control character; it's already been decoded
// by Mail_Mime, so we need the actual byte code now
// this has to be done before trying to convert to UTF-8
$char = chr(hexdec(substr('A0',1)));
$text = str_replace($char, '', $text);
// convert to UTF-8 using ConvertCharset
require 'ConvertCharset.class.php';
if( strtolower($charset) != 'utf-8' ) {
$converter = new ConvertCharset($charset, 'utf-8', false);
}
$text = $converter->Convert($text);
Then everything is spiffy. It even does the infamous Iñtërnâtiônàlizætiøn conversion, as well as accepting french, spanish, and pastes directly from MS Word :)