Not-latin symbols in SMS (PHP, SMPP) - php

I try to send SMS by PHP, SMPP protocol and must use Net_SMPP library. My code:
$smsc = new Net_SMPP_Client('xxx.xxx.xxx.xxx', xxxx);
// Make the TCP connection first
$smsc->connect();
// Now bind to the SMSC. bind() and unbind() return the response PDU.
$resp = $smsc->bind(array(
'system_id' => '*****',
'password' => '*******',
'system_type' => ''
));
$message = "Привет!";
$message=iconv("utf-8", "UCS-2", $message);
$message=bin2hex ($message);
$ssm = Net_SMPP::PDU('submit_sm', array(
'source_addr_ton' => NET_SMPP_TON_ALNUM,
'dest_addr_ton' => NET_SMPP_TON_INTL,
'source_addr' => 'AnyName',
'destination_addr' => '7**********',
'short_message' => $message,
'dest_addr_npi' => 0x01,
'data_coding' => NET_SMPP_ENCODING_ISO10646 //UCS2 coding
));
$smsc->sendPDU($ssm);
But by phone comes message with braking-encoding (so-called foursquares).
So, changing data_coding by default
'data_coding' => NET_SMPP_ENCODING_DEFAULT
gives message "1f04400438043204350442042100" (hex-code of my message).
What did I go wrong?

Resolved!
$smsc = new Net_SMPP_Client('xxx.xxx.xxx.xxx', xxxx);
// Make the TCP connection first
$smsc->connect();
// Now bind to the SMSC. bind() and unbind() return the response PDU.
$resp = $smsc->bind(array(
'system_id' => '*****',
'password' => '*******',
'system_type' => ''
));
$message = "Привет!";
$message = iconv('utf-8', "UTF-16BE", $message);
$ssm = Net_SMPP::PDU('submit_sm', array(
'source_addr_ton' => NET_SMPP_TON_ALNUM,
'dest_addr_ton' => NET_SMPP_TON_INTL,
'source_addr' => 'Kristall',
'destination_addr' => '7**********',
'short_message' => $message,
'source_addr_npi' => NET_SMPP_NPI_ISDN,
'dest_addr_npi' => NET_SMPP_NPI_ISDN,
'data_coding' => NET_SMPP_ENCODING_ISO10646
));
$smsc->sendPDU($ssm);

Related

How to add attachment to mailgun API using PHP

I have been using the mailgun API to send emails in my PHP application, When I add the attachment parameter as per the documentation, I got an error:Invalid resource type: array in /var/www/html/vendor/guzzlehttp/psr7/src/functions.php
Can someone assist?
$mgClient = new Mailgun('xxx');
$domain = "xxx";
$parameters = array(
'from' => 'xxx',
'to' => $to,
'subject' => $subject,
'text' => $text,
'attachment' = [
[
'filePath' => $attachment,
'filename' => $file_name,
]
];
);
$result = #$mgClient->sendMessage("$domain", $parameters);
I found a solution by adding the attachment array as a third parameter of the sendMessage()
$mgClient->sendMessage("$domain", $parameters, ['attachment' => ['filePath' => $file_path]]);

how can i convert a sql select query to a string

i have a sql select query im using on a scriptcase grid to find the customer email and send an email which works perfectly, i even recieve the email with the correct pdf invoice but i get an error on redirect back to the grid stating:
Fatal error: Uncaught Error: Object of class grid_jobcard_ini could
not be converted to string in C:\Program Files\Netmake.....
the code im using is:
$check_sql = "select customeremail FROM jobcard WHERE id =". [jobcard];
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})) // Row found
{
$mail = {rs[0][0]};
}
else // No row found
{
$mail = 0;
}
sc_alert($mail. ' ' .[jobcard] );
if($mail!=0)
{
$rs = sc_send_mail_api(array(
'profile' => '',
'settings' => [
'gateway' => 'smtp',
'smtp_server' => 'mail.test.com',
'smtp_port' => '587',
'smtp_user' => 'test#test.com',
'smtp_password' => '1235',
'from_email' => 'test#test.com',
'from_name' => 'test#test.com',
],
'message' => [
'html' => 'Hi! thanks so much for using our services, please find attached invoice',
'text' => '',
'to' => $mail,
'attachments' => array('C:/Program Files/NetMake/v9-php81/wwwroot/scriptcase/file/doc/test.pdf'),
'subject' => 'Your subject'
]
));
if($rs){
sc_alert({lang_mail_sended_ok} );
}
else
{
sc_error_message({sc_mail_erro});
}
}
hos do i go about making that statement a string so theres no errors?

IMAP is taking too long to load mails | Laravel IMAP

I'm using Weblex/laravel-imap to load all my mails from Gmail.
But it takes really a lot of time to load the mails when I go to mywebsite.com/api/mails.
It took 12 seconds for loading only 5 mails.
This is my config/imap.php
'accounts' => [
'gmail' => [
'host' => 'imap.gmail.com',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => 'username#gmail.com',
'password' => 'passwd',
],
..
],
..
.
This is the controller:
## web.php -> Route::get('/api/mails', 'Controller#imap');
use Webklex\IMAP\Facades\Client;
use Response;
public function imap(){
$mail = Client::account('gmail');
$mail->connect();
// dd($mail->getFolders());
$f = $mail->getFolder('INBOX');
$messages = $f->query()->since(now()->subDays(1))->get(); // today
$body = $subject = $date = $from = [];
foreach ($messages as $msg) {
array_push($body, $msg->getHTMLBody(true));
array_push($subject, $msg->getSubject(true));
array_push($date, $msg->getDate(true));
array_push($from, $msg->getFrom(true));
}
return Response::json([
'body' => $body,
'subject' => $subject,
'date' => $date,
'from' => $from
]);
}
How do I speed it up?

AWS SES on PHP error: Unable to determine service/operation name to be authorized

I am trying to send email using AWS SES using the following PHP script:
<?php
require_once("phar://aws.phar");
use Aws\Ses\SesClient;
//Open client
$client = SesClient::factory(array(
"key" => "key",
"secret" => "secret",
"region" => "region"
));
$subject = "subject";
$messageText = "text message";
$messageHtml = "<h1>formatted message</h1>";
//Send email
try{
$response = $client->sendEmail(
array(
'Source' => 'verified_email#domain.com',
'Destination' => array(
'ToAddresses' => array('an_address#domain.com')
),
'Message' => array(
'Subject' => array('Data' => $subject),
'Body' => array('Text' => array('Data' => $messageText)),
'Html' => array('Data' => $messageHtml)
)
)
);
}catch(Exception $e){
//An error happened and the email did not get sent
echo($e->getMessage());
}
?>
Whenever I run this, it goes to the catch clause and prints to the screen the message:
Unable to determine service/operation name to be authorized
This doesn't really give me any information on what's wrong and there's no documentation on the API page about this. Any ideas?

Error connecting to AuthorizeNet: in Production server only

I'm using Joomla with PHP, there is one component(payplans) is available for Joomla. In that component they configured lot of payment methods, including Authorize.net. We can select the payment method in the Joomla back-end, our client using Authorize.net so we selected Authorize.net.I did not change anything in the code, its working in our local m/c. I'm getting error only in live server even i have put the live account details not test account.
protected function _processNonRecurringRequest(PayplansPayment $payment, $data)
{
$transactionData = array(
'amount' => $payment->getAmount(),
'card_num' => $data['x_card_num'],
'exp_date' => $data['x_exp_date'],
'first_name' => $data['x_first_name'],
'last_name' => $data['x_last_name'],
'address' => $data['x_address'],
'city' => $data['x_city'],
'state' => $data['x_state'],
'country' => $data['x_country'],
'zip' => $data['x_zip'],
'email' => $data['x_email'],
'card_code' => $data['x_card_code'],
'ship_to_first_name' => $data['x_ship_to_first_name'],
'ship_to_last_name' => $data['x_ship_to_last_name'],
'ship_to_address' => $data['x_ship_to_address'],
'ship_to_city' => $data['x_ship_to_city'],
'ship_to_state' => $data['x_ship_to_state'],
'ship_to_zip' => $data['x_ship_to_zip'],
'ship_to_country' => $data['x_ship_to_country']
);
// echo "Data \n";
$transaction = new AuthorizeNetAIM();
$transaction->setSandbox(true);
$transaction->setFields($transactionData);
// print_r($transaction); exit();
// echo "response";
$response = $transaction->authorizeAndCapture();
// print_r($response);exit();
$transactionArray = $response->toArray();
// to identify it sis testing mode or not
$transactionArray['testmode'] = $this->getAppParam('sandbox', 0);
// save transaction notification and transaction id
if(isset($transactionArray['transaction_id'])){
$payment->set('txn_id', $this->getId().'_'.$transactionArray['transaction_id']);
}
$payment->set('transaction',PayplansHelperParam::arrayToIni($transactionArray));
$errors = array();
if($response->approved){
$payment->set('status',XiStatus::PAYMENT_COMPLETE);
}
else{
$payment->set('status',XiStatus::PAYMENT_PENDING);
$errors['response_reason_code'] = $response->response_reason_code;
$errors['response_code'] = $response->response_code;
$errors['response_reason_text'] = $response->response_reason_text;
}
return $errors;
}
I got error in this line
$response = $transaction->authorizeAndCapture();
please help
You have the following set to True:
$transaction->setSandbox(true);
Surely it should be set to false for the live server environment.

Categories