If you've ever used a web application, chances are quite high that you've received an email from it.
If you're building a web application, chances are you might also want to send an email from it.
Well, using MailSlurp and utopia-php/messaging, you can do that with just a couple lines!
Getting Started
1. Getting the MailSlurp API key
First we will go ahead and sign up for a free personal MailSlurp account.
Go to mailslurp.com and click on Sign Up.
Optionally setup a domain under
Inboxes > Domains
and create an inbox under theInbox
tab. We will skip for the simplicity of this tutorial.
Note that unfortunately with a free plan, you can't send emails to big providers as stated here, so you might also want to upgrade your account.
2. Using utopia-php/messaging
Now that we got the API key, you will need to install utopia-php/messaging in your PHP project, following their README:
composer require utopia-php/messaging
<?php
use \Utopia\Messaging\Messages\Email;
use \Utopia\Messaging\Adapters\Email\MailSlurp;
$message = new Email(
to: ['you@email.com'],
subject: 'Hello World',
content: '<h1>Hello World</h1>',
from: 'your-inbox-identifier@mailslurp.com'
);
$messaging = new MailSlurp('YOUR_API_KEY');
$messaging->send($message);
And simple as that, the email should be sent!
Top comments (0)