I know there are many questions related to PHPMailer, I tried most of them but no luck still,
I need to send Calendar event to gmail & outlook, which i have achieved for Gmail with below script But for outlook the ics file has send as attachment not as a calendar event.
$mail = new PHPMailer();
$mail->Host = "smtp.mandrillapp.com";
$mail->Username = SMTP_EMAIL; // defined as constant
$mail->Password = SMTP_PASSWORD; // defined as constant
$mail->Port = 587;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPDebug = 0;
$mail->isHTML(FALSE);
$mail->setFrom('k***@gmail.com', 'name');
$mail->addReplyTo('k***@gmail.com', 'name');
$mail->addAddress('v***@gmail.com', 'Gmail'); // to gmail
$mail->addAddress('k***@outlook.com','Outlook'); // to outlook
$mail->ContentType = 'text/calendar';
$ical = "BEGIN:VCALENDAR\r\n";
$ical .= "VERSION:2.0\r\n";
$ical .= "PRODID:-//LothCalendar//ATMRequest//EN\r\n";
$ical .= "METHOD:REQUEST\r\n";
$ical .= "BEGIN:VEVENT\r\n";
$ical .= "ORGANIZER;SENT-BY=\"MAILTO:k***@gmail.com\":MAILTO:ke***@outlook.com\r\n";
$ical .= "UID:".strtoupper(md5($event_id))."-lothcalendar.local\r\n";
// $ical .= "ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=k***@outlook.com;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE:mailto:k***@gmail.com\r\n";
$ical .= "ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Namekeviveks:mailto:k***@gmail.com\r\n";
$ical .= "SEQUENCE:".$sequence."\r\n";
$ical .= "STATUS:".$status."\r\n";
$ical .= "DTSTAMPTZID=Asia/Calcutta:".date('Ymd').'T'.date('His')."\r\n";
$ical .= "DTSTART:".$start."T".$start_time."\r\n";
$ical .= "DTEND:".$end."T".$end_time."\r\n";
$ical .= "LOCATION:".$venue."\r\n";
$ical .= "SUMMARY:".$summary."\r\n";
$ical .= "DESCRIPTION:some sample event description\r\n";
$ical .= "BEGIN:VALARM\r\n";
$ical .= "TRIGGER:-PT15M\r\n";
$ical .= "ACTION:DISPLAY\r\n";
$ical .= "DESCRIPTION:Reminder\r\n";
$ical .= "END:VALARM\r\n";
$ical .= "END:VEVENT\r\n";
$ical .= "END:VCALENDAR\r\n";
$mail->Subject = "Invitation: Outlook Calendar Event";
$mail->AddStringAttachment($ical, "event.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST");
$mail->Body = "Test Outlook Calendar event mail";
$mail->Ical = $ical;
//send the message, check for errors
if(!$mail->send()) {
return false;
} else {
return true;
}
I have already tried with
1. Custom Headers
$mail->addCustomHeader('MIME-version',"1.0");
$mail->addCustomHeader('Content-type',"text/calendar; name=event.ics; method=REQUEST; charset=UTF-8;");
$mail->addCustomHeader('Content-type',"text/html; charset=UTF-8");
$mail->addCustomHeader('Content-Transfer-Encoding',"7bit");
$mail->addCustomHeader('X-Mailer',"Microsoft Office Outlook 12.0");
$mail->addCustomHeader("Content-class: urn:content-classes:calendarmessage");
not worked in both Gmail and Outlook (mail send as normal text of ICS content)
2. EasyPeasyICS
$invite = new EasyPeasyICS();
$invite->addEvent('06-06-2016 08:00:00','06-06-2016 17:00:00',"TEST","TEST","");
$mail->Ical = $invite->render(false);
not worked in both Gmail and Outlook (mail send as normal text of ICS content)
3. AddStringAttachment
$mail->AddStringAttachment($ical, "event.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST");
works in gmail but sending event.ics as attachment in outlook
The only way I get this to work in Gmail, Office 365, MS Outlook, Zoho mail and iPhone Mail App was by creating and appointment in MS Outlook, download the archive, open it with a text editor like VS Code and paste it in the StringAttachment, without easypeasyics, something like this:
$ical_content = 'BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VTIMEZONE
TZID:SA Pacific Standard Time
BEGIN:STANDARD
DTSTART:16010101T000000
TZOFFSETFROM:-0500
TZOFFSETTO:-0500
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:20191203T124654Z
DESCRIPTION:Cumbre LATAM 2019\n
DTEND;TZID="SA Pacific Standard Time":20191210T220000
DTSTAMP:20191203T124654Z
DTSTART;TZID="SA Pacific Standard Time":20191210T150000
LAST-MODIFIED:20191203T124654Z
LOCATION:The Westin Lima Hotel & Convention Center
PRIORITY:5
SEQUENCE:0
SUMMARY;LANGUAGE=es:Event
TRANSP:OPAQUE
UID:040000008200E00074C5B7101A82E00800000000A06260CDADA9D501000000000000000
010000000FC95C5664F74B04B8AEB1601B7F04AD6
X-ALT-DESC;FMTTYPE=text/html:<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-mic
rosoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/
<!---- THERE IS A BUNCH OF CODE THAT OUTLOOK GENERATE HERE BUT IT OVERFLOWS THE ANSWER CAPACITY, BUT WITHOUT IT, THE APPOINTMENT DOESN'T WORK ----->
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MS-OLK-AUTOFILLLOCATION:FALSE
X-MS-OLK-CONFTYPE:0
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR';
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8'; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specicfy main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;
$mail->setFrom('[email protected]', '');
$mail->addAddress($data['email'], $data['name']);
$mail->addReplyTo('[email protected]', '');
$mail->isHTML(true);
$mail->Subject = $data['subject'];
$mail->MsgHTML($data['body']);
$mail->addStringAttachment($ical_content,'ical.ics','base64','text/calendar');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With