Skip to content

Repository files navigation

seven.io PHP SDK

Latest Stable VersionTotal DownloadsLicensePHP Version

The official PHP SDK for the seven.io SMS Gateway API

DocumentationAPI ReferenceSupportDashboard


📦 Installation

Via Composer (recommended)

composer require seven.io/api

Manual Installation

Download the latest release as ZIP file and include it in your project.

🚀 Quick Start

Send your first SMS

<?phprequire'vendor/autoload.php';
useSeven\Api\Client;
useSeven\Api\Resource\Sms\SmsParams;
useSeven\Api\Resource\Sms\SmsResource;
// Initialize the client with your API key$client = newClient('YOUR_API_KEY');
// Create SMS resource$smsResource = newSmsResource($client);
// Send SMS$response = $smsResource->dispatch(
newSmsParams('Hello from seven.io!', '+491234567890')
);
echo"SMS sent successfully! ID: " . $response->getMessages()[0]->getId();

📱 Features

SMS Messaging

  • ✅ Send SMS to single or multiple recipients
  • ✅ Bulk SMS support
  • ✅ Flash SMS
  • ✅ Unicode support
  • ✅ Delivery reports
  • ✅ Schedule messages

Voice Calls

  • ✅ Text-to-Speech calls
  • ✅ Voice message broadcasts

Number Lookup

  • ✅ HLR (Home Location Register) lookup
  • ✅ Number format validation
  • ✅ Carrier information
  • ✅ Number portability check

Other Features

  • ✅ Balance inquiry
  • ✅ Pricing information
  • ✅ Webhook management
  • ✅ Contact management
  • ✅ Analytics & Journal

💻 Usage Examples

Send SMS with custom sender

$params = (newSmsParams('Your message here', '+491234567890'))
->setFrom('YourBrand')
->setUnicode(true)
->setFlash(false);
$response = $smsResource->dispatch($params);

Send bulk SMS

$params = newSmsParams(
'Bulk message to multiple recipients',
['+491234567890', '+491234567891', '+491234567892']
);
$response = $smsResource->dispatch($params);

Schedule SMS for later

$params = (newSmsParams('Scheduled message', '+491234567890'))
->setDelay(new \DateTime('+1 hour'));
$response = $smsResource->dispatch($params);

Perform HLR lookup

useSeven\Api\Resource\Lookup\LookupResource;
$lookupResource = newLookupResource($client);
$results = $lookupResource->hlr('+491234567890');
$hlr = $results[0];
echo"Current Carrier: " . $hlr->getCurrentCarrier()->getName() . "\n";
echo"Country: " . $hlr->getCountryName() . "\n";
echo"Reachable: " . $hlr->getReachable() . "\n";
echo"Ported: " . $hlr->getPorted() . "\n";

Check account balance

useSeven\Api\Resource\Balance\BalanceResource;
$balanceResource = newBalanceResource($client);
$balance = $balanceResource->get();
echo"Current balance: €" . $balance->getAmount();

Text-to-Speech call

useSeven\Api\Resource\Voice\VoiceResource;
useSeven\Api\Resource\Voice\VoiceParams;
$voiceResource = newVoiceResource($client);
$params = newVoiceParams('+491234567890', 'Hello, this is a test call');
$response = $voiceResource->call($params);

🔧 Advanced Configuration

Initialize with signing secret (for webhook validation)

$client = newClient(
apiKey: 'YOUR_API_KEY',
signingSecret: 'YOUR_SIGNING_SECRET'
);

Error Handling

The SDK provides specific exceptions for different API error conditions:

useSeven\Api\Exception\ApiException;
useSeven\Api\Exception\InvalidApiKeyException;
useSeven\Api\Exception\MissingAccessRightsException;
useSeven\Api\Exception\ForbiddenIpException;
try {
$response = $smsResource->dispatch($params);
} catch (InvalidApiKeyException$e) {
echo"Invalid API key provided";
} catch (MissingAccessRightsException$e) {
echo"Missing access rights for this operation";
} catch (ForbiddenIpException$e) {
echo"Your IP address is not allowed";
} catch (ApiException$e) {
// Handles all other API error codes (100-903)// Common codes: 500 = Insufficient credit, 201 = Invalid sender, 202 = Invalid recipientecho"API Error: " . $e->getMessage() . " (Code: " . $e->getCode() . ")";
} catch (\Exception$e) {
echo"Error: " . $e->getMessage();
}

API Error Codes

CodeDescription
100SMS accepted and being sent
101Sending to at least one recipient failed
201Invalid sender
202Invalid recipient number
301-305Parameter validation errors
500Insufficient account credit
600Sending error occurred
900-903Authentication/authorization errors

🧪 Testing

Run the test suite with your API credentials:

# Using production API key
SEVEN_API_KEY=your_api_key php vendor/bin/phpunit tests
# Using sandbox API key
SEVEN_API_KEY_SANDBOX=your_sandbox_key php vendor/bin/phpunit tests

Run specific tests

# Test only SMS functionality
php vendor/bin/phpunit tests/SmsTest.php
# Test with verbose output
php vendor/bin/phpunit tests --verbose

📚 API Resources

The SDK provides access to all seven.io API endpoints:

ResourceDescription
AnalyticsResourceAnalytics and statistics
BalanceResourceAccount balance
ContactsResourceContact management
HooksResourceWebhook management
JournalResourceMessage history
LookupResourceNumber lookup & validation
PricingResourcePricing information
RcsResourceRCS messaging
SmsResourceSMS messaging
StatusResourceDelivery reports
SubaccountsResourceSubaccount management
ValidateForVoiceResourceVoice number validation
VoiceResourceVoice calls

🔑 Environment Variables

VariableDescription
SEVEN_API_KEYYour production API key
SEVEN_API_KEY_SANDBOXYour sandbox API key for testing
SEVEN_SIGNING_SECRETWebhook signing secret
SEVEN_TEST_RECIPIENTCustom recipient phone number for tests (default: 491716992343)

📄 Requirements

  • PHP 8.2 or higher
  • Composer (for installation)
  • ext-curl
  • ext-json

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

🆘 Support

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ by seven.io

Releases

Used by

Contributors

Languages