Quick setup examples
Laravel
Send your first email from a Laravel controller by calling the SendPing API with the Http facade.
PHP has an official package — composer require sendping/sendping — and it works from any Laravel controller or service. The example below shows the dependency-free alternative instead: POST JSON to https://www.sendping.co/api/emails with the built-in `Http` facade, a wrapper over Guzzle. See SDKs for the package.
Prerequisites
- A SendPing API key.
- A verified domain to send from.
1. Add your API key
Add your key to the application's .env file and read it with the env() helper (or via a config/ entry).
.env
SENDPING_API_KEY=mb_xxxxxxxxx2. Send email from a controller
Use the Http facade to POST the email body to the SendPing API. The easiest way to send is with the html field.
app/Http/Controllers/SendController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Http;
class SendController extends Controller
{
public function store(): JsonResponse
{
$response = Http::withToken(env('SENDPING_API_KEY'))
->post('https://www.sendping.co/api/emails', [
'from' => 'Acme <onboarding@yourdomain.com>',
'to' => ['delivered@test.sendping.co'],
'subject' => 'hello world',
'html' => '<strong>it works!</strong>',
]);
$response->throw();
return response()->json(['id' => $response->json('id')]);
}
}A successful call returns the created email's
id. See every supported field in the Send an email reference.