i want this to be converted into php, anyone please. i am doing marketing application coding to send bulk sms
from flask import Flask, request
from twilio.rest import TwilioRestClient
app = Flask(__name__)
# put your own credentials here
ACCOUNT_SID = 'YOUR_ACCOUNT_SID'
AUTH_TOKEN = 'YOUR_AUTH_TOKEN'
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
#app.route('/sms', methods=['POST'])
def send_sms():
message = client.messages.create(
to=request.form['To'],
from_='YOUR_TWILIO_PHONE_NUMBER',
body=request.form['Body'],
)
return message.sid
if __name__ == '__main__':
app.run()
Twilio developer evangelist here.
There is a whole page of documentation on how to send an SMS using Twilio and PHP right here.
In short though, to replicate the Python, you should download or install the PHP helper library to your project. Then this code should work:
<?php
require_once "vendor/autoload.php";
use Twilio\Rest\Client;
$AccountSid = "YOUR_ACCOUNTS_SID";
$AuthToken = "YOUR_AUTH_TOKEN";
$client = new Client($AccountSid, $AuthToken);
$sms = $client->messages->create(
$_REQUEST['To'],
array(
'from' => "YOUR_TWILIO_NUMBER",
'body' => $_REQUEST['Body']
)
);
echo "Sent message";
I recommend for the full instructions to follow the documentation.
Related
I purchased a number of messages , and followed all the steps
including
1. access token
2. client id and secret id
but the sms never reach the mobile number
iam using this code based on the api documentation
<?php
require 'Path to Osms ';
use \Osms\Osms;
$config = array(
'token' => 'my token'
);
$osms = new Osms($config);
$senderAddress = "tel:+200000";
$receiverAddress = "tel:+20 my number";
$message = "Hello World!";
$senderName = "Optimus Prime";
$osms->sendSms($senderAddress, $receiverAddress, $message,
$senderName);
what happens is that the number of messages at the website keeps decreasing , but the sms never arrives the mobile
Use this library instead of what you've used !
More explications are here
I am trying to download files from Google Drive using PHP client v2.0 with Drive API V3.
Is it possible to retrieve file's body and metadata in a single HTTP request?
Supplying 'alt=media' to ->files->get() returns GuzzleHttp\Psr7\Response upon which I can run ->getBody()->__toString().
If I do not provide 'alt=media', then Google_Service_Drive_DriveFile is returned that has all the metadata, but does not have body.
Question.
Is it possible to get both metadata and body in the same request?
Try something like this:
<?php
// Look at this first: https://developers.google.com/api-client-library/php/auth/web-app
require_once __DIR__ . '/vendor/autoload.php';
//change to your timezone
date_default_timezone_set('Pacific/Auckland');
$client = new Google_Client();
$client->setAuthConfig('client_secrets.json');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setIncludeGrantedScopes(true);
//change scopes to the ones you need
$client->addScope(Google_Service_Drive::DRIVE_FILE, Google_Service_Drive::DRIVE_APPDATA, Google_Service_Drive::DRIVE, Google_Service_Drive::DRIVE_METADATA);
$accessToken = json_decode(file_get_contents('credentials.json'), true);
$client->setAccessToken($accessToken);
//Refresh the token if it's expired. Google expires it after an hour so necessary
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents('credentials.json', json_encode($client->getAccessToken()));
}
$service = new Google_Service_Drive($client);
$results = $service->files->listFiles($optParams);
$fileId = 'yourfileid;
$file = $service->files->get($fileId, array('alt' => 'media'));
file_put_contents("hello.pdf",$file->getBody());
?>
I am using codeigniter and would like to implement omnipay. My development environment is windows and i use wamp server. After much struggle i installed it downloading composer and then curl and then changing the access controls in httpd.conf.
Now i am having trouble using the functions of omnipay. I have created a gateway with this code
echo 'testing the omnipay';
require 'Vendor/autoload.php';
use Omnipay\Common\GatewayFactory;
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('some_username');
$gateway->setPassword('some_password');
$gateway->setSignature('some_signature');
$gateway->setTestMode(true);
I am not sure how to proceed furthur
I would like to know if there are any tutorials or online documentation for proper use of omnipay
regards,
Nandakumar
Once you have set created the gateway, you can make a purchase with it. The documentation is in the README which comes with Omnipay.
There is an example here: https://github.com/omnipay/omnipay#tldr
and here: https://github.com/omnipay/omnipay#gateway-methods
$response = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', 'card' => $formData])->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
I'd like to have something like what the app.net site has. You click a button and get the option to send a link to your phone via SMS (or email). What are some options for implementing the sms side of things, and are there services or open source packages that provide this?
Here's a random example from app.net . Click the "Get this App" button to see what I mean.
Something like this would even work for me Send link to Phone Where "saasSMS.com" is some service that handles the whole sms side of things. Ideally could either handle that via a link or via a form post (and it would redirect back to your site on success or something).
What I don't want: A drop down that makes you pick your carrier and some php page that tries to email you #vtext.com or similar. That is just not slick enough.
You can use the ViaNett HTTP API to send SMS messages worldwide without specifying the operator.
As long as your backend supports invoking HTTP requests it will work.
Here is an example written in PHP:
<?php
// Register here to get a username and password:
// http://www.vianett.com/en/free-demonstration-account
if (vianett_sendsms('username', 'password', 'example', '+4412345678', 'Hello world', $error)) {
echo 'Success!';
} else {
echo $error;
}
function vianett_sendsms($username, $password, $from, $to, $msg, &$response=null) {
$url = 'https://smsc.vianett.no/v3/send.ashx';
$data = array(
'user' => $username,
'pass' => $password,
'src' => $from,
'dst' => $to,
'msg' => $msg
);
$qs = http_build_query($data);
$response = file_get_contents($url.'?'.$qs);
return $response == '200|OK';
}
We're getting good results from http://www.twilio.com
For direct SMS, you can try contacting a service provider and make a contract with it. If its for small projects and the server is accessible, you could put a GPRS mobile phone or modem and send with it.
My CakePHP should send an email when a button is clicked, however it doesn't. Also, the email will be displayed as a flash message if I run it in debug mode: ($this->Email->delivery = 'debug';).
Note: Email is set up to set up to use PHP mail() function.
Code to call the email function:
$this->_sendUpdateEmail( $this->Auth->user('id'), $about_id );
Email function
function _sendUpdateEmail($from_user_id, $about_id) {
$fromUser = $this->User->read(null, $from_user_id);
$users = $this->User->find('all', array(
'conditions' => array('User.distribution =' => 1)
));
# loop to send email to all users who are marked as on the distribution list
for($i = 0, $size = sizeof($users); $i < $size; ++$i) {
$user = $users[$i]['User'];
$this->Email->from = $fromUser['User']['email'];
$this->Email->replyTo = $fromUser['User']['email'];
$this->Email->to = $user['email'];
$this->Email->subject = 'Test email';
$this->Email->template = 'update';
$this->Email->sendAs = 'both'; // both = html and text
$this->set('user', $user);
$this->set('about', $about_id);
$this->Email->send();
$this->Email->reset();
}
}
Any ideas as to why the emails show in debug mode but won't actually send?
I think the reason why my emails were not sending was because there was no mail server configured on the web server my CakePHP was running on so there was no way to route the emails. However, this meant they would show up in the debug because they were generated successfully, just not sent.
In the end, I ended up using my company's Exchange mail server using the SMTP settings.
Code to use SMTP to send CakePHP emails
$this->Email->smtpOptions = array(
'port'=>'25',
'timeout'=>'30',
'host' => '192.168.0.244',
);
// Other email code here, e.g. from and to etc...
$this->Email->delivery = 'smtp';
I think the issue here is that mail server is not set right Linux comes built in with mail sending functionality but not windows (no idea on mac). look into smtp options as u can easily setup smtp email sender on Windows
Setting up smtp windows - http://publib.boulder.ibm.com/infocenter/cqhelp/v7r1m2/index.jsp?topic=/com.ibm.rational.clearquest.webadmin.doc/topics/c_config_email_smtp_win.htm
and
http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP