I am sending sms to mobile using twilio sms service in PHP http://s.test.com?v=ccc but in sms it only show http://s.test.com as a hypelink missing ?v=ccc part . how can I make it show this whole http://s.test.com?v=ccc as a hyperlink in sms ?
This is the code I am using to send sms :
function sendText($number, $id, $product_domain)
{
$short_url = 'http://s.'. $product_domain .'.com?v='.$this->toBase($id);
$client = new Services_Twilio(TWILIOSID, TWILIOTOKEN);
$client->account->messages->sendMessage("123-4567-9870", $number,
"Your Scope is complete ".$short_url." Customer Service 877.697.2673 . To disable this service reply with \"stop\"");
}
This $short_url will be generated as http://s.test.com?v=ccc
Changing http://s.test.com?v=ccc to http://s.test.com/?v=ccc fixed the issue for me.
Related
Hi I just got approved on Twilio to use it's WhatsApp messaging service.
I have no problem when testing it in the sandbox, but I got trouble when I moved it into production environment.
Based on Twilio explanation, I have to start the conversation to WhatsApp customer using one of pre-approved templates. When the customer replied, we got 24 hours of window to send freeform messages.
I already did what's in the https://www.twilio.com/docs/sms/whatsapp/tutorial/send-whatsapp-notification-messages-templates but unfortunately the given example is actually for freeform message.
Here's the script:
<?php
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
$sid = "ACxxxxxxxxxxxxxxxxxxxxx";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("whatsapp:+14155238886", // to
array(
"from" => "whatsapp:+15005550006",
"body" => "Hi Joe! Thanks for placing an order with us. We’ll let you know once your order has been processed and delivered. Your order number is O12235234"
)
);
print($message->sid);
Can anyone please help me with PHP script on how to send the WhatsApp message using this pre-approved template?
Alright, maybe some of you got here trying to ask the similar question and here's what I got after contacting the Twilio Support:
My WhatsApp API works now.
There's nothing wrong with my code nor their code (what's in their documentation https://www.twilio.com/docs/sms/whatsapp/tutorial/send-whatsapp-notification-messages-templates), actually they're using the same code to send either template message or freeform message.
Their Template Submission API to WhatsApp contains bug that creates mismatch between what we actually had in Twilio and what WhatsApp actually received. So that's why the first message I sent (even though I used the pre-approved template) always treated as freeform message thus it undelivered.
Twilio WhatsApp API is still in beta service, means bugs are expected. While it's still in beta, they recommend that we need to create templates as simple as possible and avoid formatting like bold, italics, strikethrough, etc also new lines (\n) being used in templates.
Thats all I can share and I hope you don't have problem just like I did.
Cheers!
Below is our code with predefined templates
$number = "+919XXXXXXXXX";
$to = "whatsapp:" . $number;
$from = "whatsapp:+1YYYYYYYYYY";
$msg = "Un rendez-vous de {{1}} pour {{2}} avec {{3}} et prévu le {{4}} a été créé.";
$accountSid = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
$authToken = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
$twilioClient = new Client($accountSid, $authToken);
$msg_data = array("from" => $from, "body" => $msg);
try {
$message = $twilioClient->messages->create($to, $msg_data);
$response = $message->sid ? $message->sid : '';
error_log("Twilio msg response : " . print_r($response, true));
} catch (TwilioException $e) {
error_log('Could not send whatsapp notification to ' . $number);
error_log('Could not send whatsapp TwilioException' . $e->getMessage());
}
One suggestion check for white space while creating message string. Even for a single white space they reject it.
I have integrated XERO with my php(codeigniter) website, everything i have implemented is working just fine.
I want to send the invoice through an email i have created.
I am using XeroOAuth.
//This line is working properly
$response = $this->XeroOAuth->request('GET', $this->XeroOAuth->url('Invoices/'.$invoiceId, 'core'), array(), "", 'pdf');
//but cant send email through xero api
$send_email = $this->XeroOAuth->request('POST', $this->XeroOAuth->url('Invoices/'.$invoiceId.'/Email', 'core'), array() );
As their documentation explain that, this line of code should trigger the xero send mail option, but its returning error 401
try using
XERO PHP
and you can easily send invoice using,
$invoice->sendMail();
I have sent the SMS via laravel. In twilio delivery status not showing for that SMS. If I try to sent via Javascript it shows delivery status.
$client->account->sms_messages->create($from, $sms_to, "Test SMS" , array());
Twilio developer evangelist here.
You are using the deprecated SMS/Messages endpoint with that call. The deprecated endpoint does not include delivery statuses.
Instead, you should call:
$client->account->messages->create($from, $sms_to, "Test SMS" , array());
Note that is messages not sms_messages.
Let me know if that helps at all.
You need to assign the result to a variable, then, see what the method returns in order to print something.
$message = $client->account->sms_messages->create('$from', $sms_to, "Test SMS" , array());
print_r($message);
If you need further info, check the documentation and select your version: https://twilio.github.io/twilio-php/
In my PHP project I want to integrate SMS gateway.
I have integrated HSPSMS SMS gateway.
They have given one API for this,but unfortunately I am unable to call this in proper way. I have called API after user successfully registered to site for sending SMS to user regarding same to notify he had successfully registered. Currently I am sending SMS for same but API's can send response back for SMS delivery(Successfully SMS sent or not in a JSON format).
Here is a problem- I am unable to caught the return response of SMS gateway,so it causes the Response is showing on user/Web Page.
It is a problematic for user.
For calling SMS gateway I have used PHP Header function like:
header("Location:URL of SMS Gateway");
My Code as Bellow,
<?php
include("otherpages/connection.php");
if(isset($_POST['submit1'])) {
$mname=$_POST['mname'];
$cdate=$_POST['cdate'];
$maddress1=$_POST['maddress'];
$mschool=$_POST['mschool'];
$mkendra=$_POST['centrename'];
$mmobile=$_POST['mmobile'];
$user=$_POST['user'];
$pass=$_POST['pass'];
$approved="0";
$qr="insert into tempregistration values('','$cdate','$mname','$maddress1','$mschool','$mschool','$mkendra','$mmobile','$user','$pass','$approved')";
// Code for Registration SMS
$url = 'http://sms.hspsms.com/sendSMS?username=#USERNAME#&message=Dear User,You Have Succeffully Registered to ABC.com ,Thanks&sendername=HSPSMS&smstype=PROMO&numbers=9503808004&apikey=#APIKey#';
header("Location:$url");
?>
Please help me on same or guide where I am doing right or wrong?
Any help will be appreciable.
You're sending the user's browser to the API, what you want to do is have PHP make the request and then tell the user if it was successful or not.
You may be able to use get_file_contents, but curl will give you more control.
You should have a function that will send the request to the API and return a success/failure and then display a message to the user.
Something like this (untested):
if(isset($_POST['submit1'])) {
$mname=$_POST['mname'];
$cdate=$_POST['cdate'];
$maddress1=$_POST['maddress'];
$mschool=$_POST['mschool'];
$mkendra=$_POST['centrename'];
$mmobile=$_POST['mmobile'];
$user=$_POST['user'];
$pass=$_POST['pass'];
$approved="0";
$qr="insert into tempregistration values('',
'$cdate','$mname','$maddress1','$mschool',
'$mschool','$mkendra','$mmobile','$user','$pass','$approved')";
//update to encode parameters which contain spaces
$message = urlencode('Dear User, You have successfully registered ...');
// other parametes might also contain spaces ...
$username = urlencode('#USERNAME');
$sendername = urlencode('HSPSMS');
//etc
$url = 'http://sms.hspsms.com/sendSMS?username='.$username
.'&message='.$message
.'&sendername='.$sendername
.'&smstype=PROMO&numbers=9503808004&apikey=#APIKey#';
if ($result = do_api_call($url)){
echo "SMS API returned:<br>";
echo $result;//for debugging
}else {
echo "Failure"
}
}
...
function do_api_call($url){
//this is very simplistic code to get you going ...
//use curl instead for more control
return file_get_contents($url);
}
I am currently developing a web app using PHP and using twilio, to SMS from it.
The issue I am facing is that, after reading the documentation I began using \n in my SMS body, to insert a new line, but on the receiver end, never is the new line appearing. (Tests took place on an Android 4.4.4 mobile)
Ricky from Twilio here. If you're sending a message with our PHP helper library we take care of encoding the newline for you:
$client = new Services_Twilio($account_sid, $auth_token);
$message = $client->account->messages->sendMessage(
'+15555555555', // From a Twilio number in your account
'+15555551234', // Text any number
"Hello monkey!\n how are you?"
);
If you're sending a message by making an HTTP request to our API directly you'll need to make sure the information you're sending is URL encoded. Thankfully PHP makes it pretty easy with the urlencode function:
$params =
'&From=' . urlencode("+15555555555") .
'&To=' . urlencode("+15555551234") .
'&Body=' . urlencode("Hello monkey!\n how are you?");
Hope that helps!