PHP code example of utopia-php / messaging

1. Go to this page and download the library: Download utopia-php/messaging 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/ */

    

utopia-php / messaging example snippets




use \Utopia\Messaging\Messages\Email;
use \Utopia\Messaging\Adapter\Email\SendGrid;
use \Utopia\Messaging\Adapter\Email\Mailgun;

$message = new Email(
    to: ['[email protected]'],
    subject: 'Hello World',
    content: '<h1>Hello World</h1>'
);

$messaging = new Sendgrid('YOUR_API_KEY');
$messaging->send($message);

$messaging = new Mailgun('YOUR_API_KEY', 'YOUR_DOMAIN');
$messaging->send($message);



use \Utopia\Messaging\Messages\SMS;
use \Utopia\Messaging\Adapter\SMS\Twilio;
use \Utopia\Messaging\Adapter\SMS\Telesign;

$message = new SMS(
    to: ['+12025550139'],
    content: 'Hello World'
);

$messaging = new Twilio('YOUR_ACCOUNT_SID', 'YOUR_AUTH_TOKEN');
$messaging->send($message);

$messaging = new Telesign('YOUR_USERNAME', 'YOUR_PASSWORD');
$messaging->send($message);



use \Utopia\Messaging\Messages\Push;
use \Utopia\Messaging\Adapter\Push\FCM;

$message = new Push(
    to: ['eyJhGc...ssw5c'],
    content: 'Hello World'
);

$messaging = new FCM('YOUR_SERVICE_ACCOUNT_JSON');
$messaging->send($message);
bash
composer