PHP code example of electricbrands / php-office365mailer

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

    

electricbrands / php-office365mailer example snippets


MS_TENANT_ID="your tenant id" 
MS_CLIENT_ID="your client id" 
MS_CLIENT_SECRET="your client secret"

 

use Electricbrands\PhpOffice365mailer\PhpOffice365mailer;
# use \Dotenv\Dotenv;

);
 */

/* In case that you don't have dotenv installed */
$_ENV["MS_TENANT_ID"] = "Enter your tenant id"; 
$_ENV["MS_CLIENT_ID"] = "Enter your client id"; 
$_ENV["MS_CLIENT_SECRET"] = "Enter your client secret";

$mail = new PhpOffice365mailer();

# View JWT Informations
# $mail->tokenInfo();

# Send Mail
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User');     //Add a recipient
$mail->addAddress('[email protected]');               //Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

# Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'this is a mail from ms graph just for you';
$mail->Body    = '<html>This is a html <b>mail</b> body for <i>you</i></html>';

# Add attachment
$mail->addAttachment( __DIR__ . '/testpdf.pdf', 'yourtestpdf.pdf' );

# Send
$mail->send();

# Or send and debug
# $mail->send( true );
bash
composer