$username = "info#example.com";
$hash = "*******************************************";
$test = "0";
$sender = "php sender";
$numbers = "7575757577";
$message = "verification code";
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('http://api.textlocal.in/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo"<pre>";
print_r($result);exit;
I am implementing free SMS API with CodeIgniter. Now, problem is that when I click on submit button it throws an error as mention below
{"errors":[{"code":3,"message":"Invalid login details"}],"status":"failure"}
I have no idea why it throwing this error. How can I implement this with CodeIgniter? I have also load curl library in autoload file. Please help me.
Thank You
I found a php class on the textlocal.in api documentation. Download that file and upload it to your site. Here is the download link; click.
Then just use this simple code to send a sms;
require 'textlocal.class.php';
$textlocal=new textlocal('me#textlocal.in','e215398a8820abd2c7a11a6cd5b1009d'); // email and hash
$textlocal->sendSms(['917788990011'],'Your car - KA01 HG 9999 - is due for service on July 24th, please text SERVICE to 92205 92205 for a callback','FORDIN'); // First target phone number, then the message, and then where the sms comes from
(Got the code from here; click)
If you have anymore questions, just ask :)
Related
I have 10 ios apps with subscription in app purchases. I need one subscription purchase to be valid accross the 10 apps. Thus I require server-side receipt validation. The flow is like this: When the customer pays for the subscription, the receipt is sent to the Firebase DB and from there, I require a PHP script that takes in the receipt data . as input and sends a 'POST' request to the App store. The App store would then validate the receipt and return a JSON object back. We then overwrite the old receipt with the latest copy. Also, whenever the user logs in to any of the apps, we repeat this process and update the receipt to make sure the subscription of the user is still valid. How do I do this in Firebase? If I cannot, can you please suggest any alternatives?
I have seen on some forums that Firebase 'cloud functions' might be able to such things. However, I am not exactly sure. Also, I am not quite adamant on using PHP. If I am able to achieve the same outcome using a different scripting language, I would be very happy.
Thanks.
Here is a sample of the PHP script:
<?php
function getReceiptData($receipt)
{
$fh = fopen('showme.txt',w);
fwrite($fh,$receipt);
fclose($fh);
$endpoint = 'https://sandbox.itunes.apple.com/verifyReceipt';
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $receipt);
$response = curl_exec($ch);
$errno = curl_errno($ch);
$errmsg = curl_error($ch);
curl_close($ch);
$msg = $response.' - '.$errno.' - '.$errmsg;
echo $response;
}
foreach ($_POST as $key=>$value){
$newcontent .= $key.' '.$value;
}
$new = trim($newcontent);
$new = trim($newcontent);
$new = str_replace('_','+',$new);
$new = str_replace(' =','==',$new);
if (substr_count($new,'=') == 0){
if (strpos('=',$new) === false){
$new .= '=';
}
}
$new = '{"receipt-data":"'.$new.'","password":"<INSERT YOUR IN-APP PURCHASE SHARED SECRET HERE>"}';
$info = getReceiptData($new);
?>
I am integrating SMS gateway for the very first time. I want to send sms when someone pays to the website. I am using the following code:
<?php
$pay="1000";
$msg="Arivind";
echo $url="http://yourdomainname.com/api/swsend.asp?username=xxxxxx&password=xxxxxx&sender=SENDERID&sendto=91XXXXXXXXX&message=Dear'$msg' Thanks for making payment of Rs '$pay'";
$c=curl_init();
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($c,CURLOPT_URL,$url);
$contents=curl_exec($c);
curl_close($c);
echo "SMS Successfully sent";
?>
Now if i am using variable in body of message, the message is not sent but if i use static message the message is getting delivered to the number.
The static message doesnt solve my purpose as i need the message to be sent to different person, the variable used ie $msg will have different name of people & fetched from database.
KINDLY SUGGEST.
Using variables between single quotes ' does not convert it into dynamic values. Also its better to RestApi in simple PHP function:
function CURLcall($number, $message_body){
$api_params = "swsend.asp?username=xxxxxx&password=xxxxxx&sender=SENDERID&sendto=91XXXXXXXXX&message=$message_body";
$smsGatewayUrl = "echo $url="http://yourdomainname.com/api/";
$smsgatewaydata = $smsGatewayUrl.$api_params;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, smsgatewaydata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
// Use file get contents when CURL is not installed on server.
if(!$output){
$output = file_get_contents($smsgatewaydata);
}
}
Call above function as:
$message_body = urlencode("Dear $msg Thanks for making payment of Rs $pay");
CURLcall('918954xxxxx',$message_body);
Please note: urlencode is useful to avoid errors in GET method as it convert space into encoded format http://php.net/manual/en/function.urlencode.php
You can also use http_build_query to convert your variables into a nicely formatted URL.
<?php
$fname = 'Matthew';
$lname = 'Douglas';
$amount = 1000;
$message = "Thanks for your payment of Rs {$amount}.";
$urlComponents = array(
'firstName' => $fname,
'lastName' => $lname,
'message' => $message
);
$url = 'http://yourdomainname.com/api/swsend.asp?';
echo $url . http_build_query($urlComponents);
?>
I have a codeigniter base website and I have tried making forgot password by Phone and Email using Codeigniter framework to change password notification.And email is already working but I don't know how to send message to phone using codeigniter??
And one of my friends told me that use Curl function to send message to phone.But I didn't have any prior idea about CURL function so I searched on google but I couldn't figure out how to do this.
Would you please give me proper suggestion about how to send message to phone using codeigniter.
Any kind of help would be highly appreciated.
Thanks in advance.
Here is a simple code-igniter helper which you need to save as helpers/sendsms_helper.php
function sendsms($number, $message_body, $return = '0') {
$sender = 'SEDEMO'; // Can be customized
$smsGatewayUrl = 'http://springedge.com';
$apikey = '62q3xxxxxxxxxxxxxxxxxxxxxx'; // Need to change
$textmessage = urlencode($textmessage);
$api_element = '/api/web/send/';
$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$number.'&message='.$textmessage;
$smsgatewaydata = $smsGatewayUrl.$api_params;
$url = $smsgatewaydata;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch);
curl_close($ch);
if(!$output){ $output = file_get_contents($smsgatewaydata); }
if($return == '1'){ return $output; }else{ echo "Sent"; }
}
How to use:
You can use below function anywhere in project to send sms:
Call sendsms function Ex. sendsms( '919918xxxxxx', 'test message' );
Please make sure to Load sendsms helper as $this->load->helper('sendsms_helper');
There are many companies that provide api for the same. I have used twilio for some time and find it reliable. The code for same can be
<?php
require "Services/Twilio.php";
$AccountSid = ""; //get from twilio
$AuthToken = ""; //get from twilio
$client = new Services_Twilio($AccountSid, $AuthToken);
$sms = $client->account->messages->sendMessage(
$tNumber, // Your twilio number
$number, // Number you want to send to
$message // Message you want to sms
);
Hope this helps. Again there are many other services out there also that you can look into
MY SMS CODE: I have purchased the sms gate from third party.I am having some issue with that when I integrate in my website. I have listed my issue.can anyone guide me what I have to do further?Read my question?
<?php
$ID = 'xxxxxx';
$Pwd = 'xxxxx';
$PhNo = '1234567890,123456789';
$Text = 'welcome to US';
$url="http://t.dialmenow.info/sendsms.jsp?user=$ID&password=$Pwd&mobiles=$PhNo&sms=$Text&senderid =";
//echo $url;
$ret = file($url);
//echo $ret;
echo $ret[9];
?>
**I have problem with my message and delivery report.**
1.If you see the $Text variable $Text=welcome to US if I give space after first word the message is not coming to my mobile.
2.In api documentation they have given how to check delivery status. Here is the api delivery status code.they have given sample code. I want to know how to write the sample delivery status code for above php code.
http://t.dialmenow.info/getDLR.jsp?userid=username&password=password&messageid=1,2&externalid=1,2 &drquantity=X&fromdate=yyyy-mm-dd hh:mm:ss&todate=yyyy-mm-ddhh:mm:ss&redownload=yes&responcetype=xml
Explanation:
messageid=>When you send a message you will get an unique message id from API and you have to use this
messageid=>for getting the deliver status for that message.
externalid=>unique sms serial no which you will get in response.
Drquantity=>it means how many delivery status you want from Dialmenow application
Try encoding your message using the below
$msg = urlencode($Text)
Havent used file() but you could try implementing via cURL. Pls ensure that cURL in installed in the server where the code will be executed.
$ID = 'xxxxxx';
$Pwd = 'xxxxx';
$PhNo = '1234567890,123456789';
$Text = 'welcome to US';
$msg=urlencode($Text);
$url="http://t.dialmenow.info/sendsms.jsp?user=$ID&password=$Pwd&mobiles=$PhNo&sms=$msg&senderid=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER ,true);
$result = curl_exec($ch);
curl_close($ch);
I've created an employment application that allows applicants to upload their resume in pdf, doc, or docx extensions. I then email their information and resume to Human Resources using Sendgrid.
I've found through testing that when sending the email I receive an error:
Parameter attachment[resume.pdf] is not utf8
How can I fix this issues, should I encode every file that is uploaded to utf-8 before attaching it to the email? Will this create any issues or severally modify an users uploaded resume?
Here is my PHP Curl code I use to send via the SendGrid API:
(Note: I have to use the REST API, SMTP is not configured on the clients web server)
<?php
$mail['from'] = 'humanresources#email.org';
$mail['fromname'] = 'Human Resources';
$mail['to'] = 'person#email.com';
$mail['subject'] = character_limiter('Employment: '. $application['position'], 50);
$mail['html'] = '<p><strong>Name:</strong> '.$application['firstname'].' '.$application['lastname'].'</p>';
$mail['html'] .= '<p><strong>Position:</strong> '.$application['position'].'</p>';
$mail['html'] .= '<p><strong>Date:</strong> '.mdate('%m/%d/%Y %g:%i %A', $application['timestamp_saved']).'</p>';
$mail['html'] .= '<p><strong>Email:</strong> '.$application['email'].'</p>';
$mail['files['.$application['pdf'].']'] = '#saved_applications/'. $application['pdf'];
//Sendgrid Credientals
$mail['api_user'] = 'sendgrid_user';
$mail['api_key'] = 'sendgrid_pass';
print_r($mail);
// Generate curl request
$session = curl_init('https://sendgrid.com/api/mail.send.json');
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $mail);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
$output = json_decode($response, TRUE);
print_r($output);
?>
The code you have should work (and worked when I tested it).
You may want to use the PHP library, rather than flat cURL. You'll be able to send attachments, from the web Web API by doing the following:
<?php
$sendgrid = new SendGrid('username', 'password');
$mail = new SendGrid\Mail();
$mail->
addTo('humanresources#email.org')->
...
addAttachment('saved_applications/'. $application['pdf']);
$sendgrid->web->send($mail);
?>
Perhaps instead of using sendgrid's web services API to send these messages, simply use phpmailer and send the messages through sendgrid by way of SMTP using their outgoing mail server smtp.sendgrid.net. I'm sure you won't get this error if you send the messages this way. See example at https://github.com/PHPMailer/PHPMailer.