Send ical meeting invite using SMTP PHPMailer

Send ical meeting invite using SMTP PHPMailer

PHPMailer is an open source PHP library to send emails safely and easily using SMTP credentials from a web server. You can easily send text mail, invite, meetings, calendar with attachment using PHPmailer. PHPMailer support Gmail, Outlook, Office356 and other mail servers.

First you need to download PHPMailer library from Github or you can also download via compose. Composer is the recommended way to install PHPMailer. Just add this line to your composer.json file:

"phpmailer/phpmailer": "^6.5"

or run

composer require phpmailer/phpmailer

After download copy the contents of the PHPMailer folder and paste into your working directories and load each class file manually:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

Send meeting invite in smtp mail using php

Send meeting with ical attachment code:


require 'vendor/autoload.php';

$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = '';                       // Specify main and backup server
$mail->SetFrom('', 'Theknowledgedda');
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'username';                   // SMTP username
$mail->Password = 'passwordd';               // SMTP password
//$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
$mail->Port = 25;                                    //Set the SMTP port number - 587 for authenticated TLS
$mail->addAddress('');  // Add a recipient
$mail->isHTML(true);                                  // Set email format to HTML

$location           = "Alaska";
    $date               = '20211216';
    $startTime          = '0800';
    $endTime            = '0900';
    $subject            = 'Millennium Meeting';
    $desc               = 'This email is a reminder for you. Please accept!';

$organizer          = 'Darth Vader';

    $organizer_email    = '';   
    $participant_name_1 = 'Doe';
    $participant_email_1= '';

    $text = "BEGIN:VCALENDAR\r\n
    PRODID:-//Deathstar-mailer//theforce/NONSGML v1.0//EN\r\n
    UID:" . md5(uniqid(mt_rand(), true)) . "\r\n
    DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z\r\n

$headers = "From: Sender\n";
$headers .= 'Content-Type:text/calendar; Content-Disposition: inline; charset=utf-8;\r\n';
$headers .= "Content-Type: text/plain;charset=\"utf-8\"\r\n"; #EDIT: TYPO
$mail->Subject = $subject;
$mail->Body = $desc; 
$mail->AltBody = $text; // in your case once more the $text string
$mail->Ical = $text; // ical format, in your case $text string

$mail->addAttachment('invite.ics');         // Add attachments

if($mail->send()) {
   echo 'Message has been sent';
   echo 'Message sent fail.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;


One Comment on “Send ical meeting invite using SMTP PHPMailer”

Leave a Reply

Your email address will not be published. Required fields are marked *