1. Go to this page and download the library: Download emailit/emailit-laravel 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 Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;
Mail::to('[email protected]')->send(new WelcomeEmail($user));
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class WelcomeEmail extends Mailable
{
use Queueable, SerializesModels;
public function __construct(
public readonly User $user,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Welcome to Our App',
);
}
public function content(): Content
{
return new Content(
view: 'emails.welcome',
);
}
}
use Emailit\Laravel\Facades\Emailit;
// Send an email via the API directly
$email = Emailit::emails()->send([
'from' => '[email protected]',
'to' => ['[email protected]'],
'subject' => 'Hello from Emailit',
'html' => '<h1>Welcome!</h1>',
]);
echo $email->id;
echo $email->status;
use Emailit\Exceptions\AuthenticationException;
use Emailit\Exceptions\RateLimitException;
use Emailit\Exceptions\ApiErrorException;
use Emailit\Laravel\Facades\Emailit;
try {
Emailit::emails()->send([...]);
} catch (AuthenticationException $e) {
// Invalid API key (401)
} catch (RateLimitException $e) {
// Too many requests (429)
} catch (ApiErrorException $e) {
// Any other API error
echo $e->getHttpStatus();
}
use Emailit\EmailitClient;
class EmailController extends Controller
{
public function send(EmailitClient $emailit)
{
$email = $emailit->emails()->send([
'from' => '[email protected]',
'to' => ['[email protected]'],
'subject' => 'Hello',
'html' => '<p>Hi there!</p>',
]);
return response()->json(['id' => $email->id]);
}
}