PHP code example of jornatf / msgraph-mailer

1. Go to this page and download the library: Download jornatf/msgraph-mailer 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/ */

    

jornatf / msgraph-mailer example snippets




namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

class PostController extends Controller
{
    public function sendMail()
    {
        try {
            $msgraph = MsGraphMailer::mail('[email protected]')
                ->to(['John Doe:[email protected]', '[email protected]', $otherRecipients])
                ->subject('A simple email')
                ->body('<h1>Send a simple email to one recipient.</h1>')
                ->send();
        } catch (\Exception $e) {
            return $e->getMessage();
        }

        return "Email sended!";
    }
}



// First, instantiate response with your Msgraph mailbox (recipient(s), a subject and a content (HTML);

// You can add Cc and/or bcc with the same way (optionally):
$msgraph->cc(array $ccRecipient);
$msgraph->bcc(array $bccRecipient);

// Optionally, you can add one or many attachments:
$msgraph->addAttachment(array $attachment = [
    'name' => $filename,
    'contentType' => $contentType,
    'content' => $contentBytes
]);
// and repeat if you have many attachments.

// Last, send your mail:
$msgraph->send();