1. Go to this page and download the library: Download am-naguib/am-sender library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use AMSender\Facades\AMSender;
use AMSender\Exceptions\ValidationException;
try {
// This will throw ValidationException - device name too short
AMSender::createDevice('Hi');
} catch (ValidationException $e) {
echo $e->getMessage(); // "Device name must be at least 3 characters long."
}
try {
// This will throw ValidationException - phone number too short
AMSender::send([
'message' => 'Hello!',
'receivers' => ['123'], // Too short
'device_ids' => ['device-1']
]);
} catch (ValidationException $e) {
echo $e->getMessage(); // "Phone number at index 0 is too short. Minimum 5 characters ly!";
} catch (ValidationException $e) {
echo "Validation error: " . $e->getMessage();
}
use AMSender\Facades\AMSender;
use AMSender\Exceptions\InvalidImageException;
use AMSender\Helpers\ImageHelper;
try {
$result = AMSender::send([
'message' => 'Check this image!',
'receivers' => ['+1234567890'],
'device_ids' => ['device-1'],
'image' => 'https://example.com/image.jpg'
]);
} catch (InvalidImageException $e) {
echo "Image error: " . $e->getMessage();
// Get suggestions for fixing the URL
$suggestions = ImageHelper::getImageUrlSuggestions('https://example.com/image.jpg');
foreach ($suggestions as $suggestion) {
echo "- " . $suggestion . "\n";
}
}
// Test an image URL before sending
$imageUrl = 'https://example.com/image.jpg';
$testResult = ImageHelper::testImageUrl($imageUrl);
if (!$testResult['is_accessible']) {
echo "Image URL is not accessible\n";
foreach ($testResult['errors'] as $error) {
echo "Error: " . $error . "\n";
}
}
if ($testResult['warnings']) {
foreach ($testResult['warnings'] as $warning) {
echo "Warning: " . $warning . "\n";
}
}
// Common error scenarios:
// 1. URL not accessible
"Image URL is not accessible. Please check: 1) URL is publicly accessible, 2) URL points to a valid image file, 3) Image server allows external access."
// 2. Invalid file type
"The provided URL does not point to a valid image file. Please ensure the URL ends with a valid image extension (jpg, jpeg, png, gif, webp, bmp)."
// 3. URL format issues
"Image must be a valid URL format."
"Image URL must use HTTP or HTTPS protocol."
// ✅ All these formats are accepted
$receivers = [
'+1234567890', // International format
'01234567890', // Local format
'123-456-7890', // With hyphens
'(123) 456-7890', // With parentheses
'123 456 7890', // With spaces
'', // Empty - will be filtered out automatically
' ', // Whitespace only - will be filtered out
];
// Result: Empty numbers are automatically removed
// Final receivers: ['+1234567890', '01234567890', '123-456-7890', '(123) 456-7890', '123 456 7890']
$allReceivers = ['+1111111111', '+2222222222', /* ... many more */];
$chunks = array_chunk($allReceivers, 100); // Process 100 at a time
foreach ($chunks as $chunk) {
try {
AMSender::send([
'message' => 'Bulk message',
'receivers' => $chunk,
'device_ids' => ['device-1'],
'delay_time' => 2 // Add delay between batches
]);
sleep(5); // Wait between batches to avoid rate limits
} catch (Exception $e) {
Log::error("Batch failed: " . $e->getMessage());
}
}