Sending a meeting invite and HTML email with PHP - php

I am trying to send an email to people who register for a course on this site. I found this PHP code that worked once for perfectly and then decided to not work at all.
Basically, it will send an email to the person and the normal mail will be perfect however, the calendar event will not show up in their outlook calendar.
Here is the code I am using:
<?php
function sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime,
$subject, $description, $location)
{
$domain = 'example.com';
//Create Email Headers
$mime_boundary = "----THIS WILL WORK!!!----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$headers .= "Content-class: urn:content-classes:calendarmessage\n";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Eastern Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20091101T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20090301T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
return ($mailsent)?(true):(false);
}
$from_name = "from Name";
$from_address = "from Address";
$to_name = "to Name";
$to_address = "toaddress#example.com";
$startTime = "11/09/2014 18:00:00";
$endTime = "11/09/2014 19:00:00";
$subject = "I HOPE THIS WORKS";
$description = "I REALLY HOPE THIS WORKS";
$location = "Joe's House";
sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject,
$description, $location);
?>
My question is: Is there any wrong that you can see with my code and if so what can I do to fix it?

use this:
$startTime = "11-09-2014 18:00:00";
$endTime = "11-09-2014 19:00:00";

Related

VCalendar and PHP sending meeting request but email is not requesting a reply

I am using PHP and VCal to send a meeting request to a user. The issue is, when the use receives the request, it does not give them the option to "Accept/Decline" the meeting. This is happening in OUTLOOK. The accept and decline button options are greyed out and the when the email is opened it says "No response required" I would like to make it so that the user has the option to decline or accept and DOES require a response. If I try to accept a test invite on my iphone, a message pops up that says "Your response to the invitation cannot be sent." Not sure what tweak I need to make in my VCAL code. Any idea?
EDIT TO POST: I figured out how to make the calendar event allow for accepting and denying caldendar invites by changing the 'METHOD:PUBLISH' instead of request.
EDITED ISSUE: Now the issue I am running into is that the user receiving the Vcalendar invite is able to edit the subject, and location and date of the event. How do I disable the ability to edit Calendar Invite details using VCal?
Thank you.
//Create Email Headers
$mime_boundary = "----Meeting Booking----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$headers .= "Content-class: urn:content-classes:calendarmessage\n";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
$ical =
'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN' . "\r\n" .
'CALSCALE:GREGORIAN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:America/Chicago:' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:200911 01T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20090301T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
//'ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="'.$to_name.'";'.
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
The line starting with ATTENDEE defines the information required to respond to the request. In your code, it looks strange:
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n"
As far as I know, the :MAILTO part belongs to the CN. Here's a line from an iCal file that works properly in Outlook and on iPhone:
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Peter:MAILTO:peter#pan.com
The e-mail address needs to be the address of the recipient of your request, not yours (obviously).

PHP meeting invite using iCal object, resulting appointment is not editable

I'm using a function I found online to generate meeting invites in OutLook using PHP. I have made an online calendar where the users are assigned work orders on a day-to-day basis. I'm trying to "sync" this one with Outlook. Everything works fine, except the resulting Outlook invitation is uneditable. The user must be able to edit the start time and duration of the assignment in Outlook.
The calendar body looks like this:
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:W. Europe Standard Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20181028T030000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10' . "\r\n" .
'TZOFFSETFROM:+0200' . "\r\n" .
'TZOFFSETTO:+0100' . "\r\n" .
'TZNAME:CET' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20190331T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:+0100' . "\r\n" .
'TZOFFSETTO:+0200' . "\r\n" .
'TZNAME:CEST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART:'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND:'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
Is there any parameter I can change in order to make the appointment editable?
The organizer is always the same as the attendee in this case.
The headers look like this:
$mime_boundary = "----Meeting Booking----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$headers .= "Content-class: urn:content-classes:calendarmessage\n";
Tony, My understanding is that an ics file that is 'synced' (ie a url that is subscribed to) will not be editable in any application other than the creating one (OR if the receiving application is connected with the creating application, in which case all events will be 'synced' anyway).
If the receiver imports (Ie NOT subscribe to a URL or 'sync') the ics contents into one of their calendars then they should be able to edit it, however it will not 'sync' then.

Exporting Calendar and Sending Mail Outlook PHP

I get an Error: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp64\www\stage\views\mailtest.php on line 125
I didn't know how to modified the port.
I had another code for sending and recieve mails and it's worked but now i need to create an event Calendar with sending mail.
function sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location)
{
$domain = 'hotmail.com';
//Create Email Headers
$mime_boundary = "----Meeting Booking----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$headers .= "Content-class: urn:content-classes:calendarmessage\n";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Eastern Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20091101T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20090301T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
return ($mailsent)?(true):(false);
}
$from_name = "Omar Krichene";
$from_address = "krichene30#hotmail.com";
$to_name = "Omar Krichene";
$to_address = "krichen30#gmail.com";
$startTime = "11/07/2018 18:00:00";
$endTime = "11/07/2018 19:00:00";
$subject = "My Test Subject";
$description = "My Awesome Description";
$location = "Krichene House";
sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location);
The script is not able to connect to the SMTP server.
Have you checked if an SMTP server is running on the localhost or the computer the script is running from at port 25?
If not you'll need to provide a working SMTP server address and login to it.

ics attachment not reflected in outlook calendar using php?

I have used this function send icalevent to outlook calendar.
But this function works in gmail but not in outlook calendar. In outlook I am getting message alone. Please anyone tell me what is wrong with the code:
\\ function to send icalevent to outlook calendar
function sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location){
$domain = 'exchangecore.com';
//Create Email Headers
$mime_boundary = "----Meeting Booking----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$headers .= "Content-class: urn:content-classes:calendarmessage\n";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Eastern Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20091101T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20090301T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message .= 'Content-Type:text/calendar; Content-Disposition: inline; charset=utf-8;\r\n';
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
return ($mailsent)?(true):(false);
}
$from_name = "webmaster";
$from_address = "info#sageit.in";
$to_name = "Joseph";
$to_address = "gopinathan#domain.com";
$startTime = "11/6/2015 18:00:00";
$endTime = "11/6/2015 19:00:00";
$subject = "My Test Subject";
$description = "My Awesome Description";
$location = "Joe's House";
sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location);
exit;
Have to remove the boundary from function. now the function is working fine
Change this to
$message = "--$mime_boundary\r\n";
To
// $message = "--$mime_boundary\r\n";

sending .ics file as calender not as attachment using php

<?php
function sendIcalEvent($to_address, $startTime, $endTime, $subject, $description, $location)
{
$from_name = 'ivan.k';
$from_address = 'ivan.k#cspl.com';
$to_name = "Ramya";
$domain = 'cspl.com';
//Create Email Headers
$mime_boundary = "----Meeting Booking----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$mime_boundary\"\n";
// $headers .= "Content-type: text/calendar; method=REQUEST; charset=UTF-8\r\n";
$headers .= "Content-class: urn:content-classes:calendarmessage\n";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
//status / url / recurid /
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
// 'CALSCALE:GREGORIAN' . "\r\n" .
// 'METHOD:PUBLISH' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Eastern Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20091101T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20090301T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
if($mailsent){
return true;
} else {
return false;
}
}
I am sending the calender request to outlook through mail using php.It have the html body content.In this the meeting.ics is going as a attachment but i want that to be send as calender request that should added automatically to the calender . if i give content type as text/calender in header the html body becomes empty.Can anyone help me with some code?
Thanks in advance
Hi got another one problem.when i set the $starttime as "2013-01-23 13:00:00" it have to get added to the calender at 01 PM on 23-01-2013 but it is added to 06:30 PM on 23-01-23.I want it to send at IST format how to do that.any sugessions?
You need to add Content-Disposition to you message part:
Try to change this:
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
To this:
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= 'Content-Disposition: attachment';
$message .= 'Content-Transfer-Encoding: base64';
Not sure that this work cause i didn't tested and it can behave differently on each mail client.
Along with the ics attachment even add another body part to your email body with following headers.
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= 'Content-Transfer-Encoding: base64';
In the content of this body part put the ics file content.
This should work!!
Try to use this:
header("Content-type:text/calendar");
header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');

Categories