I'm using sendgrid/sendgrid-php the repo on github to send transnational emails. Today I've updated the library, the new one uses the API v3 whereas I used v2 before. I've changed the code as per their examples, here is a dump of my SendGrid\Mail object:
The problem is that I'm constantly receiving the 400 BAD REQUEST error without any additional info:
What am I doing wrong? The mail object seems to be correct.
I'm trying to send the email the following way:
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$request_body = [creating the mail object];
$response = $sg->client->mail()->send()->post($request_body);
I was having the same issue and discovered all personalizations need to be strings with double quotes. In your example:
$md_email_id = (string)26921
More info https://github.com/sendgrid/sendgrid-php/issues/264
Related
Hi I am trying to use coinbase api,api implementation is Working fine but facing problem on notification. Accroding to documentation I have created Notification url and codes are bellow
<?php
require_once('vendor/autoload.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$apiKey=" xxxx";
$apiSecret="xxxx";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$raw_body = file_get_contents('php://input');
$signature = $_SERVER['HTTP_CB_SIGNATURE'];
$authenticity = $client->verifyCallback($raw_body, $signature); // boolean
if($authenticity){
$data = json_decode($raw_body, true);
mail("sahid4745#gmail.com","Coinbase Payment Notifications",print_r($order, true));
}
$message=$raw_body;
mail('sahid4745#gmail.com', 'My Subject', $message);
?>
But this is producing error as Notice:
Undefined index: HTTP_CB_SIGNATURE in /home/exhakduz/api/webhooks.php
on line 38
I Don't know actually what is server_cb_signature, if some one can explain that will be great help for me.
All entries in $_SERVER that begin with HTTP_ reflect the contents of HTTP request headers. The header name is converted to uppercase and - is converted to _. So if the client sends a header like Foo-Bar: blah, the value of $_SERVER['HTTP_FOO_BAR'] will be "blah".
The Coinbase documentation says that notifications are secured with a CB-SIGNATURE header, so $_SERVER['HTTP_CB_SIGNATURE'] should contain the contents of this header. I'm not sure why you're not getting it. Your code is exactly like the example code in the documentation.
Maybe there's something in your server configuration that's filtering out nonstandard headers?
I'm trying to send optional parameters to a Twilio Studio Flow Trigger using PHP. I followed the example shown in the Twilio Studio REST API docs and was successful triggering a new Flow using the (required) sender and recipient phone numbers.
use Twilio\Rest\Client;
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "my_auth_token";
$twilio = new Client($sid, $token);
$execution = $twilio->studio->v1->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
->executions
->create("+15555559876", "+15555551234");
After getting the basic communications working, I now want to pass a couple parameters to the Flow. Unfortunately, I couldn't find any PHP examples that include optional parameters. (The docs mention how to access parameter values in the widgets with {{flow.data.parameterName}}, but not how to generate the request in PHP.)
The answer is probably easy and obvious but I can't figure it out and would appreciate any guidance.
Received an answer from Twilio Support.
$data = ["parameters" => ["foo" => "bar"]];
$flow = $twilio->studio->v2->flows("FWxxxxx");
$flow->executions->create($to, $from, $data);
Optional parameters are now passing through and can be used by widgets in the Studio Flow.
Sending twilio message from my api returns this error
Twilio sending message The requested resource /2010-04-01/Accounts//Messages.json was not found
this is how I send a message. anyone incountered a problem?
$this->client = new \Services_Twilio($sid, $token);
return $this->client->account->messages->sendMessage($from ,$to, $message);
this is the documentation I followed
https://www.twilio.com/docs/api/rest/sending-sms
How do I create Messages.json
I used this https://github.com/twilio/twilio-php on laravel 4.2
Another Twilio developer evangelist here. Think I might be able to help.
The error message you got was this:
The requested resource /2010-04-01/Accounts//Messages.json was not found
The key point is the URL, particularly the double slash in the middle. That is where your Account Sid should be, thus leading to the 404 error.
In this case, I would double check how you are setting $sid. Make sure it is assigned before you try to create the Twilio client object.
Hi Twilio developer evangelist here.
Sorry to hear you're having trouble with your code.
You seem to not have posted your complete code, so I don't see where you actually require the library.
I have however written an example which worked for me.
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = 'AC';
$token = '01';
$client = new \Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
'+44', // From a valid Twilio number
'+44', // Text this number
"Hello monkey!"
);
I have removed some sensitive data on the code, but if you replace that with your token and numbers, you should be able to send a text message correctly.
Also, just in case you have the contents of the 'Services' folder elsewhere, make sure your paths are correct.
You have entered messages when it should be sms_messages.
CHANGE
$this->client->account->messages->sendMessage($from ,$to, $message);
INTO
$this->client->account->sms_messages->create($from ,$to, $message);
Also make sure that you are running this code inside a class otherwise you need to remove the $this-> from your code and use a local varible.
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!
I need to retrieve an auth token from an Android device (client side) using AccountManager.getAuthToken and then re-use it via Zend_Gdata (server side)
When using the calendar 'cl' authTokenType things work as expected,
Android source:
String calendarToken = getAuthToken(account, 'cl' ...
PHP source:
$token = // value retrieved via Android 'calendarToken'
$client = new Zend_Gdata_HttpClient;
$client->setClientLoginToken($token);
$gData = new Zend_Gdata($client);
$feed = $gData->getFeed("http://www.google.com/calendar/feeds/default/private/full");
This does work, however when using the Gmail 'mail' authTokenType things are not so smooth
Android source:
String mailToken = getAuthToken(account, 'mail' ...
PHP source:
$token = // value retrieved via Android 'mailToken'
$client = new Zend_Gdata_HttpClient;
$client->setClientLoginToken($token);
$gData = new Zend_Gdata($client);
$feed = $gData->getFeed("https://mail.google.com/mail/feed/atom/");
This keeps throwing a 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 401.
I tried to follow guidelines for the various Google Data APIs with no luck
The only reason you should see a difference between AuthSub requests to two services is a scope issue. Review item number three in the AuthSub docs and check to make sure the token you're using has access to GMail.