Add BCC to Woocoomerce transactional email sent through Sendinblue - php

We are currently using Sendinblue as mail marketing provider and did set it up on our Wordpress/Woocommerce shop to handle marketing and transactional emails now.
Before that, we used to send some transactional woocommerce transactional email, such as order_completed in bcc to one of our own email addresses. This is necessary for certain internal processes.
Hence Sendinblue has taken over, this function isn't being triggered, or more like is triggered but doesn't get processed through Sendinblue anymore.
Although, I found an API call that could actually do exactly that: https://developers.sendinblue.com/reference#sendtransacemail
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sendinblue.com/v3/smtp/email",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"bcc\":[{\"email\":\"something#domain.com\"}]}",
CURLOPT_HTTPHEADER => array(
"accept: application/json",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
As well as this: https://apidocs.sendinblue.com/tutorial-sending-transactional-email/
Though, I'm absolutely unsure where to add this in order to trigger BCC through Sendinblue.
Would be amazing, if someone could point me in the right direction.
Kind Regards
Chris

you don't have to use the API calls to be able to use Sendinblue for Email. What you should do is just making Sendinblue as your Email Server by entering your Sendinblue server details as your Wordpress default SMTP server. You can use the following code to do so.
If you do the above your website will function normally and all triggers will work just fine, the only thing if that your website will use Sendinblue as it's Email Server and all the sent emails will be logged to your Sendinblue account.
How to get your Sendinblue SMTP account working:
https://help.sendinblue.com/hc/en-us/articles/209463245--How-can-I-get-my-SendinBlue-SMTP-account-activated-
Very simple article to help you with configuring your SMTP:
https://help.dreamhost.com/hc/en-us/articles/215526937-Configuring-the-WP-Mail-SMTP-plugin
Good luck!

Related

Cannot set cookies dynamically in api request on a site with laravel and angular

Hello everyone I have an app where I need to make an API request and that app is made of laravel and angular. Laravel for the backend and angular is for the front end. The API is for subscribing a user to a specific task. On my app, I need to make an API request which needs cookies that are being generated from the backend ( most probably I'm not sure ). So those cookies enable my API to work properly. I have all the things ready but I can't set the cookies dynamically. The problem is I'm not sure where are those cookies are being generated from. I have created a custom function that calls the API with some specific parameter and then it just subscribes the user with that privilege that the user was subscribed to.
My app workflow is like below
on the angular, I submit the payment form
after the form submission my app goes to the payment sandbox provided by the third party ( this is a completely different server )
then after a successful payment transaction it redirects to my laravel app and calls the custom function that I made and tries to subscribe the user with the features user paid for.
on the last step, I can't get the cookie that was needed to make the user subscribe to the plan that they paid for. This time I need to get the cookie from the API which I can get by making the request manually. as it's a payment procedure I can not make it manual and the whole process needs to go automatically.
My API is okay no problem with that The problem is that I can not make the cookies dynamically and also I am not being able to use those dynamically generated cookies each time a request is made.
following is the main api function
/**
* Create a new subscription.
*
* #return JsonResponse
*/
public function store()
{
$this->authorize('update', Subscription::class);
$this->validate($this->request, [
'user_id' => 'required|exists:users,id|unique:subscriptions',
'renews_at' => 'required_without:ends_at|date|nullable',
'ends_at' => 'required_without:renews_at|date|nullable',
'plan_id' => 'required|integer|exists:billing_plans,id',
'description' => 'string|nullable',
]);
$subscription = $this->subscription->create($this->request->all());
return $this->success(['subscription' => $subscription]);
console.log('running');
}
following is my custom function
public function apicall(Request $request){
$curl = curl_init();
$xsrf_token = request()->Cookie("X-XSRF-TOKEN");
$cookie = request()->Cookie("Cookie");
curl_setopt_array($curl, array(
CURLOPT_URL => 'localhost:4200/secure/billing/subscriptions',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"user_id": 3,
"renews_at": "2021-01-29 18:00:00",
"plan_id": 1,
"description": "null"
}',
CURLOPT_HTTPHEADER => array(
$xsrf_token,
$cookie,
'Host: localhost:4200',
'Referer: http://localhost:4200/admin/subscriptions?page=1&per_page=15',
'Origin: http://localhost:4200',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
return redirect('http://localhost:4200/dashboard')->with('status', 'Success');
}
On web.php I have configured routes and everything else. My API and payment redirection all are working well but The users are not being subscribed or I can say may API is not being able to verify the request's owner or the request's validation so it's not being able to give me any 200 response. It just gives me 302 with the found tag. So how should I set the cookie dynamically so that the request cookie can be matched by the system's subscription cookie?
Can anyone help me with this? I need to solve this as soon as possible.

"Invalid platform app" error using Instagram Basic Display API

I am trying to use Instagram Basic display API but when I post the authorization code to get the access token I keep getting the following error
{"error_type": "OAuthException", "code": 400, "error_message":
"Invalid platform app"}
I am following all the steps mentioned here -> https://developers.facebook.com/docs/instagram-basic-display-api/getting-started and Yes I am using the Instagram app ID and It's client secret which is in Products -> Instagram -> Display and following is the URL I am sending the request
"https://api.instagram.com/oauth/access_token?client_id=".$app_id."&client_secret=".$app_secret."&grant_type=authorization_code&redirect_uri=".$redirecturi."&code=".$code,
I ran into this same issue. Problem was I was using the Facebook App ID and App Secret instead of the Instagram App ID & App Secret. You must go to the "Instagram Basic Display" section on the Facebook developers site then scroll down until you find the Instagram App ID & Secret.
If you are using Postman, do remember it's a POST request. Use form data
When you exchange the code you need to use a POST request.
From the looks of your url, you've formed it as a GET request with all the parameters as part of the url rather than as form data. Try sending the parameters as part of the post body instead
Working example code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.instagram.com/oauth/access_token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('client_id' => '{client_id}','client_secret' => '{client_secret}','grant_type' => 'authorization_code','redirect_uri' => '{redirect_uri}','code' => '{code}'),
CURLOPT_HTTPHEADER => array(
"Content-Type: multipart/form-data; boundary=--------------------------780367731654051340650991"
),
));
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
I have got this error for the below reason.
If any case, App Id and Secret Key are blank then this type of error is generated. so we can first test first that that app id and secret key must be the correct one. I know that this is a very normal thing that we can notice easily. But sometimes, we can not notice some simple things.

Errors using MailChimp API adding email address to list

I am trying to add email addresses to my mailchimp mailing list but am getting an error saying
Access Denied
You don't have permission to access "http://us9.api.mailchimp.com/3.0/lists/######/members/" on this server.
Reference #18.1e89655f.1546511382.213522b5
I have just created the API key and haven't done much with MailChimp before. I think the list ID is correct, I just grabbed it from the URL of my actual list in a browser https://us9.admin.mailchimp.com/lists/members/?id=######
<?php
$email = '#########.##';
$authToken = '#######################-us9';
$email_list = '######';
$postData = array(
"email_address" => "$email",
"status" => "subscribed",
"merge_fields" => array(
"NAME"=> "",
"PHONE"=> "")
);
$ch = curl_init('https://us9.api.mailchimp.com/3.0/lists/'.$email_list.'/members/');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization: apikey '.$authToken,
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
$response = curl_exec($ch);
var_dump($response);
?>
The API list ID is not the same as the browser one. (Don't ask me why). To find out the API list ID, use the API Playground. https://developer.mailchimp.com/
I think the IP of your server is blacklisted for Mailchimp. You should contact Mailchimp and ask if the server IP is blacklisted for them.
It was a transient error for me, which went away after a couple of minutes. If it doesn't then somehow Akamai has probably blacklisted you and you need to contact Mailchimp (as Akamai does not handle Mailchimp specific requests directly).
If you look in the response headers, it says Server: AkamaiGHost, which I assume is the proxy Mailchimp is using. Also the response is text/html, which does not match Mailchimp's own documented error formats–another sign that it is the proxy blocking you and not Mailchimp itself.

How to send sms via php when i have the API link

I have a link from the via which I can send sms. It works when I put it in the address bar and fill the required get params and press enter. But how can I load it in the middle of controller action (the framework is Yii2 if that matters) ? I tried with mail() but couldn't reach any result.
The link is like below:
http://sms.***********.com/httpApi/Send.aspx?phone=359.........&body=message&username=xxx&password=xxx
Can I make it with plain php or I have to it via javascript ? Thank you in advance!
cURL allows transfer of data across a wide variety of protocols, and is a very powerful system. It's widely used as a way to send data across websites, including things like API interaction and oAuth. cURL is unrestricted in what it can do, from the basic HTTP request, to the more complex FTP upload or interaction with an authentication enclosed HTTPS site. We'll be looking at the simple difference between sending a GET and POST request and dealing with the returned response, as well as highlighting some useful parameters.
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'YOUR API URL',
CURLOPT_USERAGENT => 'cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close().
You should use сURL.
$query = http_build_query([
'phone' => '359.........',
'body' => 'message',
'username' => 'xxx',
'password' => 'xxx'
]);
$c = curl_init();
curl_setopt($c , CURLOPT_URL , 'http://sms.***********.com/httpApi/Send.aspx/?' . $query);
curl_exec($c);
curl_close($c);

How to integrate Quickbooks Online API using PHP?

I am new to Quickbooks API. I have found APIs list under API Exolorer link in Quickbooks. They have shown the Request URI & Request Headers that are needed for making the API call. I can understand that. But how to call that URI or how to integrate that API with PHP is not exactly specified. I tried to call the URI and get the results using curl,but it didn't succeed. I have lost lot of time for this integration. I have searched google in all possible way. But most of the results coming related to PHP SDKs. But I need to integrate the Quickbooks Online API.
The Request URI for creating an entity is looks like below.
https://{{baseurl}}/v3/company/{{companyid}}/account
Please help me to sort this out.
As most people suggested, using the PHP SDK is going to be the easier way for integrating QuickBooks Online with PHP: https://github.com/intuit/QuickBooks-V3-PHP-SDK
However, using plain PHP cURL is also possible, but a few concepts you need to understand before making the API call:
1) OAuth 1.0 protocol
It is what most developer get confused of. QuickBooks Online use OAuth 1.0 as authorization protocol. You need to spend sometime to understand how it worked. For documentation, you can read it here: https://developer.intuit.com/docs/0100_quickbooks_online/0100_essentials/000500_authentication_and_authorization/connect_from_within_your_app
However, I suggest you play with the OAuth playground, it gives you a feeling for how it looked like when you implement it: https://appcenter.intuit.com/Playground/OAuth/IA/ (fill your Consumer key and secrets, click on Connect to Quickbooks Button)
During the process, it will return something called: RealmID. That is the companyid in QBO, put it on the URL.
2) The base URL
When you create an app at developer.intuit.com, under keys tab, you will see Development Keys and Production Keys. The corresponding keys at the right side is what you need to fill for the {baseurl} part(For example, besides development keys, there is place called "Accounting Sandbox Url" : "sandbox-quickbooks.api.intuit.com"). For each API entity endpoint, refer to the documentation: https://developer.intuit.com/docs/api/accounting/customer
3) Authorization header
You are unlikely to implement it by yourself for OAuth 1.0. Twitter has a good link for how to use the Access Token and Access Token secrets from step 1) to generate signature: https://dev.twitter.com/oauth/overview/creating-signatures
You will put the signature as part of the authorization header.
If you are using POSTMAN, they have OAuth 1.0 as authorization protocol available for you. Here is an example
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://sandbox-quickbooks.api.intuit.com/v3/company/193514340994122/account/1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: OAuth oauth_consumer_key=\"qyprdDjYtPpiEpbwFQZuUoAjubpVqm\",oauth_token=\"lvprdfblXv4LqNVhIv2WH2JebiSZgNs9POiEoCJxMwEhqbgc\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1494441064\",oauth_nonce=\"cfh0b7\",oauth_version=\"1.0\",oauth_signature=\"KqpN9ximPGWnWJBaXg1Vs9urJLY%3D\"",
"cache-control: no-cache",
"postman-token: 7c570691-c6cd-a706-67a0-984c5ddb1e6a"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

Categories