Hey there, fellow developer! Ready to supercharge your PHP application with GetResponse's powerful email marketing features? You're in the right place. We'll be using the getresponse/sdk-php
package to make our lives easier. Let's dive in!
Before we start, make sure you've got:
First things first, let's get that SDK installed:
composer require getresponse/sdk-php
Easy peasy! Now we're ready to rock and roll.
Time to initialize our client. It's as simple as:
use GetResponse\SDK\GetResponseClientFactory; $client = GetResponseClientFactory::createWithApiKey('your-api-key');
Boom! You're authenticated and ready to go.
Let's start with something simple:
$account = $client->accounts()->get(); echo $account->getEmail();
Adding a contact is a breeze:
$newContact = $client->contacts()->create([ 'email' => '[email protected]', 'campaign' => ['campaignId' => 'your-campaign-id'] ]);
Updating and deleting? Just as easy:
$client->contacts()->update('contact-id', ['name' => 'John Doe']); $client->contacts()->delete('contact-id');
List your campaigns:
$campaigns = $client->campaigns()->getList(); foreach ($campaigns as $campaign) { echo $campaign->getName(); }
Create a new one:
$newCampaign = $client->campaigns()->create([ 'name' => 'Awesome Campaign', 'languageCode' => 'EN' ]);
Time to spread the word:
$client->newsletters()->sendDraft('newsletter-id', ['selectedCampaigns' => ['campaign-id']]);
Don't forget to catch those exceptions:
try { // Your API calls here } catch (\GetResponse\SDK\Exception\MalformedResponseDataException $e) { // Handle API errors }
Want to level up? Look into:
And there you have it! You're now equipped to integrate GetResponse into your PHP application like a pro. Remember, the official documentation is your friend for more detailed info.
Now go forth and conquer those email marketing campaigns! 💪📧