Outlook Calendar - Mailing with php

Joined: 11/28/2008

Hi,

I need to send an event through a php based application to outlook in the form of a calendar invitation. This is what i have so far

CODE
BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
ATTENDEE;CN=attender1@mail.com;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:attender1@mail.com
ATTENDEE;CN="Someones Name";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:attender2@mail.com
ORGANIZER:MAILTO:email@domain.com
DTSTART:20050128T000000Z
DTEND:20050128T003000Z
LOCATION:Head offce
TRANSP:OPAQUE
SEQUENCE:0
UID:040000008200E00074C5B7101A82E00800000000E010BD266504C5010000000000000000100
000004938F36FEDDF5248A54AB3A9EA980DBF
DTSTAMP:20050127T184133Z
DESCRIPTION:When: 27 January  2005 17:00-17:30 (GMT-07:00) Mountain Time
 (US & Canada).\nWhere: Head
 offce\n\n*~*~*~*~*~*~*~*~*~*\n\nYou have a board meeting scheduled!\n
SUMMARY:Testing
PRIORITY:5
CLASS:PUBLIC
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR

This is what I got when I sent it to a non outlook calendar email client. How do I send this to a outlook calendar email client as an "event or appointment" through php mail - with variables added to the code.

I can do the variables, just have no idea how to sent it.

Thanks!

As it is now, it comes through as a text attachment. Does anybody have any ideas on what to do? Thanks!

JustMe

bob
bob's picture
Joined: 11/28/2008
Do you know if Outlook needs

Do you know if Outlook needs to read these items as part of the header? (I'm guessing it does) If so, when you send via PHP mail, try adding the info to the header section instead of as an attachement.

You may want to look through MSDN for some ideas, too.

Joined: 11/28/2008
thanks bob - I tried sending

thanks bob - I tried sending it in the headers, but it is not working - no sign of it even.

Does anybody know of a good way to do this so that it doesn't come through as an email, but a event in the vcalendar?

Thanks

JustMe

Joined: 11/28/2008
Are there mime headers for

Are there mime headers for the vcalendar?

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Yes there are - I am not sure

Yes there are - I am not sure which is correct, but even when I use them, it does not work.
content-type: text/calendar
and I also found this one
content-type: text/x-vcalendar

I tried using these in the headers, but then I do not know where to put the other information (the vcalendar code).

If this can not be done, I could do it another way. The first would be prefered, but perhaps if I let the user upload their vcalendar onto the server, and then from that code I could make a calendar. I do not know if this is possible, but if the first scenario does not work, then this one will do.

Thanks for all of your replies.

JustMe

Joined: 11/28/2008
[subscribes to thread]This

[subscribes to thread]

This will be really useful info when it all gets figured out! Please post some sample PHP code when you get things squared away for all of us to enjoy! /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

Joined: 11/28/2008
Hi again, I played around

Hi again, I played around with some code that I found at http://www.scit.wlv.ac.uk/rfc/rfc24xx/RFC2447.html but that code is not intended for mail with php I think. Here is what I have thus far:

CODE
<?php
$message = 'Board meeting - be there';
$subject = 'Appointment Scheduled';
$email = 'sentto@domain.com';
$headers = 'Content-Type:text/calendar; method=REQUEST; charset=US-ASCII;\r\n';
$headers .= 'Content-Transfer-Encoding: 7bit;';
$headers .= '
  BEGIN:VCALENDAR
  PRODID:-//My Calendar Test//EN
  METHOD:REQUEST
  VERSION:2.0
  BEGIN:VEVENT
  ORGANIZER:mailto:organizer@domain.com
  ATTENDEE;ROLE=CHAIR;ATTSTAT=ACCEPTED:mailto:email1@domain.com
  ATTENDEE;RSVP=YES;TYPE=INDIVIDUAL:mailto:email2@domain.com
  DTSTAMP:19970611T190000Z
  DTSTART:19970701T170000Z
  DTEND:19970701T173000Z
  SUMMARY:Phone Conference
  UID:calsvr.example.com-8739701987387771
  SEQUENCE:0
  STATUS:CONFIRMED
  END:VEVENT
  END:VCALENDAR
';
if (mail($email, $subject, $message, $headers)) {
echo 'Congrats on a job well done';
};
 
?>

THat does NOT work. I am almost certain that I have something wrong in the headers. When the email comes through, it has all the header info and then the message.

Any suggestions? Thanks.

JustMe

Joined: 11/28/2008
This part of this line looks

This part of this line looks fishy....

QUOTE
$headers = 'Content-Type:text/calendar; method=REQUEST; charset=US-ASCII;\r\n';

I've never seen that used in MIME Email headers before...

Joined: 11/28/2008
I don't know where the

I don't know where the vcalendar part comes in, but I sent an appointment from my work account (Exchange 2003) using the Web mail interface, and this is what I got (email addresses etc edited)

CODE
Return-path: <myemail@work.com>
Envelope-to: testemail@domain.com
Delivery-date: Fri, 28 Jan 2005 23:20:47 -0500
Received: Ip addresses, times etc
Received: by email server etc
    id <DX9X7CAW>; Sat, 29 Jan 2005 12:20:13 +0800
Message-ID: Randomstringthing
From: Paul Davey <myemail@work.com>
To: testemail@domain.com
Subject: Test Appointment from work
Date: Sat, 29 Jan 2005 12:20:54 +0800
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2657.72)
content-class: urn:content-classes:calendarmessage
x-mimeole: urn:content-classes:calendarmessage
Content-Type: text/plain;
    charset="utf-8"

Type:Single Meeting
Organizer:Paul Davey
Start Time:Saturday, January 29, 2005 12:30 PM
End Time:Saturday, January 29, 2005 1:00 PM
Time Zone:(GMT+08:00) Perth
Location:Home again

*~*~*~*~*~*~*~*~*~*

Message Body Here

In Outlook, it prompted me to accept/decline the appoiuntment when I opened the message (not an attachement). The message format was simple enough!

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Bobbymac Thanks for your

Bobbymac Thanks for your reply - the email which you recieved is the exact email that I need php mail to send - do you know what sort of headers are associated with php mail and how they would be sent?

Thanks so much.

JustMe

Joined: 11/28/2008
Hi Ladies and Gents,So I have

Hi Ladies and Gents,

So I have now tried everything that my mind can think - including taking out the method, changing it etc... I will be more than willing to read from tutorials or articles if any of you guys do know about this. And yes, tubbytreats I will post all the script here if I ever figure out how /wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />.

Thanks!

JustMe

bob
bob's picture
Joined: 11/28/2008
Something you could try with

Something you could try with your bit of code (or using Paul's) is explicitly adding a "\r\n" to the end of each header line. That may be the reason the headers are being dumped into the message.

The "\r\n" is the standard delimiter for each header. And since they are escape characters, they must be used in double quotes. Single quotes will treat them as a literal.

Here's a slight adjustment to your code using the data presented by Paul.

CODE
<?php
$message = 'Board meeting - be there';
$subject = 'Appointment Scheduled';
$email = 'sentto@domain.com';
$headers .= '';
$headers .= "content-class: urn:content-classes:calendarmessage\r\n";
$headers .= "x-mimeole: urn:content-classes:calendarmessage\r\n";
$headers .= "Content-Type: text/plain;charset=\"utf-8\"\r\n"; #EDIT: TYPO
$headers .= "Type:Single Meeting\r\n";
$headers .= "Organizer:Paul Davey\r\n";
$headers .= "Start Time:Saturday, January 29, 2005 12:30 PM\r\n";
$headers .= "End Time:Saturday, January 29, 2005 1:00 PM\r\n";
$headers .= "Time Zone:(GMT+08:00) Perth\r\n";
$headers .= "Location:Home again\r\n";

if (mail($email, $subject, $message, $headers)) {
echo 'Congrats on a job well done';
};

?>

Joined: 11/28/2008
Figured this was appropriate

Figured this was appropriate to the conversation...

HOW TO VIEW MESSAGE SOURCE IN OUTLOOK 2003:
http://www.outlook-tips.net/howto/view_source.htm

I can't get either Bob's or bobbymac's code to work here sending PHP mail() from a Windows IIS 6.0 server to an Outlook email account. I get an email, but it just has plaintext in it, and is NOT formatted as an Outlook "Appointment Request" message.

Joined: 11/28/2008
Here's what happens when I

Here's what happens when I send a message from Outlook 2003 to an external webmail account:

QUOTE
Return-path: <emailAddress@domain.com>
Envelope-to: emailAddress@domain.com
Delivery-date: Thu, 03 Feb 2005 10:42:39 -0500
From: Name of Recipient <emailAddress@domain.com>
To: emailAddress@domain.com
Subject: This is the subject
Date: Thu, 3 Feb 2005 10:42:37 -0500
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2657.72)
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C50A06.FCD0B848"

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C50A06.FCD0B848
Content-Type: text/plain;
charset="iso-8859-1"

When: Thursday, February 03, 2005 11:00 AM-11:30 AM (GMT-05:00) Eastern Time
(US & Canada).
Where: This is the location

*~*~*~*~*~*~*~*~*~*

This is the body: Please plan to be at the meeting.

------_=_NextPart_001_01C50A06.FCD0B848
Content-Type: text/html;
charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2658.2">
<TITLE>This is the subject</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2 FACE="Arial">When: Thursday, February 03, 2005 11:00 AM-11:30 AM (GMT-05:00) Eastern Time (US &amp; Canada).</FONT>
<BR><FONT SIZE=2 FACE="Arial">Where: This is the location</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">*~*~*~*~*~*~*~*~*~*</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">This is the body: Please plan to be at the meeting.</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C50A06.FCD0B848--

bob
bob's picture
Joined: 11/28/2008
I've updated the previously

I've updated the previously posted code. There was a typo following the content-type. Sorry, I don't use a calendaring program so I couldn't test. With all that I learned, I'll install one soon enough. /wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />

To send in vCalendar format just send a .vcs file as an attachment. The contents of the file should have everything between and including the BEGIN: and END:VCALENDAR lines that was posted earlier. The suggestion about placing them as headers was a mistake.

Here are some key points that I've learned (some resources below).
1. There are two main calendar formats - vCalendar(.vcs) and iCalendar(.ics). Outlook seems to have its own thing but can support the others.
2. vCalendar is much easier to implement.
3. Method=Request. The method here tells Outlook if this is a request, reply, etc. It is not GET, POST, etc.
4. There are various levels of compliance, even across versions of Outlook, that need to be considered when developing. Basically, the newer the software, the more robust.

Other resources:
Using PHP to Make Basic vCalendar/iCalendar Events
MSDN Calendaring
Outlook 2000 and Outlook 2002 iCalendar interoperability problems
iCalendar PHP Class
vCalendar PHP Class
Outlook Appointments, ASP and vCalendar
vCal code for GeekLog
iCalendar File Builder Demo

Joined: 11/28/2008
HiThanks for your input -

Hi

Thanks for your input - sorry i couldn't relpy. I was away for the weekend. I am looking through all the posts closely and will post when I figure it out or get stuck.

Thanks.

JustMe

John Fallentine
John Fallentine's picture
Old Thread but maybe it will help the next coder

Ok

After spending the whole day pasting code from several other sites, I accidentally found some code that will work. In the code, a user is registering for an event, and this script will set up a calendar event in the Outlook so they can accept/deny/etc

Please note that the Description is currently not working (tomorrow's task) for some reason.

$to = $formVars['email'];
$subject = "Training Registration";
$message = "Thank you for participating in the Technical Certification training program.\n\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
$messaje = "BEGIN:VCALENDAR\n";
$messaje .= "VERSION:2.0\n";
$messaje .= "PRODID:PHP\n";
$messaje .= "METHOD:REQUEST\n";
$messaje .= "BEGIN:VEVENT\n";
$messaje .= "DTSTART:" . $date_array[1] . $momth . $day1 . "T080000\n";
$messaje .= "DTEND:" . $date_array[1] . $momth . $day2. "T170000\n";
$messaje . "DESCRIPTION: You have registered for the class\n";
$messaje .= "SUMMARY:Technical Training\n";
$messaje .= "ORGANIZER; CN=\"Corporate\":mailto:training@corporate.com\n";
$messaje .= "Location:" . $location . "\n";
$messaje .= "UID:040000008200E00074C5B7101A82E00800000006FC30E6C39DC004CA782E0C002E01A81\n";
$messaje .= "SEQUENCE:0\n";
$messaje .= "DTSTAMP:".date('Ymd').'T'.date('His')."\n";
$messaje .= "END:VEVENT\n";
$messaje .= "END:VCALENDAR\n";
$headers .= $messaje;
mail($to, $subject, $message, $headers);

Finally works!!!

Joined: 05/06/2011
message is empty

I have implemented the above code seeme to work fine but the
message ($message = "Thank you for participating in the Technical Certification training program.\n\n";)
in email is empty .Please help out.