Sending SMS using PHP API with unicode message - php

I trying to send SMS via RoutoMessaging PHP API. I readed all documentation and examples what i was able to find.
They have PHP example script for sending SMS in unicode format:
<?php
// include RoutoSMS class
include("RoutoTelecomSMS.php");
// creating object
$sms = new RoutoTelecomSMS;
// setting login parameters
$sms->SetUssms->SetOwnNum("44792838383838");
$sms->SetType("unicode");
// get values entered from FORM
$sms->SetNumber($number);
$message="04220432043E04580435002004370435043B0435043D04350020043E0
44704380020044104430020043C04380020043F0430043C043504420020043F043E
043C044304420438043B0435002E002E002E";
$sms->SetMessage($message);
// send SMS and print result
$smsresult = $sms->Send();
print $smsresult;
?>
What i not understand is how i can transform text from submited string to this code needed for including in $message.
Can anyone suggest function to convert text for $message please?
I currently work with PHP version 5.3.3.

The message you are sending is a Cryllic text. It's probably in Serbian. It reads as "Твоје зелене очи су ми памет помутиле..."
Decoding
header('Content-Type: text/html; charset=utf-8');
$str = "04220432043E04580435002004370435043B0435043D04350020043E044704380020044104430020043C04380020043F0430043C043504420020043F043E043C044304420438043B0435002E002E002E";
foreach(str_split($str, 4) as $char) echo "&#x{$char};";
And this is how you would encode the message
$string = "Твоје зелене очи су ми памет помутиле...";
$string = mb_convert_encoding($string, 'UCS-2', 'utf8');
for($i =0; $i < strlen($string); $i++)
echo strtoupper(bin2hex($string[$i]));

Related

PhpMailer, how do I write the variable value correctly for multiple addCC email address?

I have a PhpMailer working code as follow: (short version)
(the variable already defined before hand)
// Sender and recipient settings
$mail->setFrom($pengirim_email, $pengirim_nama);
$mail->addAddress($untuk_email, $untuk_nama);
$mail->addReplyTo($pengirim_email, $pengirim_nama);
Next, I add multiple email address for CC mail:
$mail-->addCC('aaa#gmail.com','Abdul');
$mail-->addCC('bbb#gmail.com','Borat');
It work as expected.
Now since I'm planning that the email address will come from the SQL query, so for the time being I want to know how do I have to fill the SQL 'CarbonCopy' column table with multiple email addresses - by trying to make a "hardcoded" variable value. So I try like this as the replacement for the addCC above:
$tembusan="'aaa#gmail.com','Abdul';'bbb#gmail.com','Borat'"; //not working
$CC = explode(';', $tembusan); //not working
for ($i = 0; $i < count($CC); $i++) {$mail->addCC($CC[$i]);} //not working
But it throw me an error like this :
Error in sending email. Mailer Error: Invalid address: (cc):
'aaa#gmail.com','Abdul'
So I change the $tembusan into like this:
$tembusan="aaa#gmail.com,Abdul;bbb#gmail.com,Borat"; //not working
It gives me almost the same like the error before:
Error in sending email. Mailer Error: Invalid address: (cc):
aaa#gmail.com,Abdul
Next, I try also this kind of code :
$tembusan="'aaa#gmail.com','Abdul';'bbb#gmail.com','Borat'"; //not working
$CC = explode(';', $tembusan); //not working
foreach($CC as $CCemail){$mail->AddCC($CCemail;} //not working
And it also throw the same error:
Error in sending email. Mailer Error: Invalid address: (cc):
'aaa#gmail.com','Abdul'
If I echo the last code like this foreach($CC as $CCemail){echo $CCemail. '<br/>';}, it give me a result like this :
'aaa#gmail.com','Abdul'
'bbb#gmail.com','Borat'
In my real code, I have a valid email address. The email address in the code above is just for an example.
Where did I do wrong ?
PS
btw, if I remove the "name" for the email address:
$tembusan="aaa#gmail.com;bbb#gmail.com"; //working
$CC = explode(';', $tembusan); //working
foreach($CC as $CCemail){$mail->AddCC($CCemail;} //working
it runs as expected (but in the gmail, the CC name is aaa and bbb).
Please do a further explode . try
$tembusan="aaa#gmail.com,Abdul;bbb#gmail.com,Borat";
$CC = explode(';', $tembusan);
for ($i = 0; $i < count($CC); $i++) {
$DD = explode(',', $CC[$i]);
$mail->addCC($DD[0], $DD[1]);
}
Please note that I have removed the ' characters . (you may use str_replace of PHP to eliminate these characters)

PHP Mailer sends received data to email

I have php script, which receives data from javascript application and sends them to email.
Here is how I get the data:
$postdata = file_get_contents('php://input');
$request = json_decode($postdata, true);
And here is how I convert variables:
$premiumTotal = $request['premiumTotal'];
$variant = $request['variant'];
$risksBuilding = $request['risksBuilding'];
When the variable is string - everything works fine.
But the last one is an Array ($risksBuilding) and in e-mail I receive the word "Array".
How can I output this variable ?

How can I retrieve Unicode characters from IMAP in PHP?

I'm trying to parse an email that is partially written in English and partially written in Japanese using PHP. Here's the code I have so far:
if ($mbox = imap_open($mailbox, $username, $password)) {
$inbox = imap_check($mbox);
$total = (int) $inbox->Nmsgs;
$min = max(1, $total - 10);
// fetch 10 most recent emails
if ($total > 0 && ($emails = imap_fetch_overview($mbox, "{$min}:{$total}"))) {
foreach ($emails as $email) {
$body = imap_body($mbox, $email->uid, FT_UID);
// for testing purposes
echo $body;
// parsing logic here
}
}
}
So as you can see I'm just echoing out the plaintext body of the email, just to test things, and here's part of the echoed response I get when I run this script:
Your Japanese word of the day is: ç”·ã®å­
However, the following is what I should see in place of that, based on what's actually in the email:
Your Japanese word of the day is: 男の子
So clearly something's being lost in translation (pun intended). I'm using some simple string manipulation to try and parse the Japanese characters, and then insert them into a MySQL database. However, it's currently inserting those gobbledygook characters instead. What am I missing?
Edit: I'm using PHP version 5.4.45
So I'm not really sure how to get this working in PHP 5. I decided to try upgrading my server to PHP 7 and suddenly all of the code just started working.

Getting Mail body In PHP

What I am doing:
First I am trying to get email and save the reply of user in my database.
For this I am using PHP imap method to get mail from my email address.
Code:
function get_email()
{
//define server, email , password
$server = '{server.example.com:143}INBOX';
$user_name = 'login';
$user_pass = 'password';
$mail = imap_open( $server , $user_name , $user_pass );
$headers = imap_num_msg($mail);//counting the no of msg
for ($i = 1; $i <= $headers ; $i++)
{
$body = imap_fetchbody($mail, $i ,1);
$body = explode(">",$body);
$body = $body['0'];
$body = substr($body, 0, -5);
echo "<pre>";
echo "/-/-/-/-/-/".$body."/-/-/-/-/-/";
echo "</pre>";
}
// close the connection
imap_close($mail);
}
Now:
The Result that i am getting from $body = imap_fetchbody($mail, $i ,$i); is this:
Okay What new in it.
On Thu, Feb 12, 2015 at 4:56 PM, admin wrote:
> My name is admin!
>
>
but only wanted a the msg body that Okay What new in it. . So I explode() the massage and get the first element of array and remove the last line.
Problem:
I could not remove last line the current result of this program Is:
Okay What new in it.
On Thu, Feb 12, 2015 at 4:56 PM, admin
Even I have add "/-/-/-/-/-/" symbol but the symbol are not showing.
Your approach is not ideal, and this answer will not be ideal either. Because frankly what you are trying to accomplish can be quite difficult, because previous messages in a thread on emails will be different depending on client used and you cannot trust the user either (the thread below the 'body' could have been altered by the user etc.)
Using explode by '>' is not ideal, because what if it is part of the message?
exploding by \n> is a no go too because a user might inline responses as #Michael_Berkovski said.
Anyways here is my solution:
$body = preg_replace('#(\n>.*?)+$#','',$body);
This will reduce the following:
This is the body
> And this is a comment within the body
Also just the body
>Previous messages
>here
>> Even indented who cares?
to:
This is the body
> And this is a comment within the body
Also just the body
For trying very hard I come to a solution that ask user to reply with '#' at the end of the massage. As I notice there are different types of replies from different mailing services but all services show reply first.
Code:
$msgno = imap_num_msg($mail);
for ($i = 1; $i <= $msgno ; $i++)
{
$body = imap_fetchbody($mail, $i ,1);
$body = explode("#",$body);
$body = $body['0'];
echo $body;
echo "<br>";
}
From this I got my desire result.

imap_fetchbody - Encoded body error

I am trying to fetch a particular section of an email body using:
$message = imap_fetchbody ($imap_stream,$n,1);
This works fine for emails sent using Outlook, Hotmail, Yahoo etc. But when I try and fetch the body of the an email sent from a Blackberry or Andriod device, the message is encoded and scrambled such as:
xmb250IHN0eWxlPSdjb2xvcjojRjk3MWIxMDNiMTEyYjExOGI0N2I1MWI1
Although the body is encoded, the header is fine. How do I decode the message body of en email sent from an Android or Blackberry device?
Thank you,
Chris.
You should be able to run imap_fetchstructure to get the encoded value. If that value equals 3 you need to decode via imap_base64.
I've used the following before (Can't remember if it was ever tested with sent mobile email before though):
$structure = imap_fetchstructure($stream, $msgno);
$text = imap_fetchbody($stream, $msgno, $partnum);
if($structure->encoding == 3) {
$text = imap_base64($text);
} else if($structure->encoding == 4) {
$text = imap_qprint($text);
}

Categories