Hi all,
my boss want me to send an calendar invitation event to Microsoft Outlook
i have tried many time already and it still give me the result
"This is no a valid internet calendar file"

and here my code:

$vcal = "BEGIN:VCALENDAR";
  $vcal .= "VERSION:2.0";
  $vcal .= "PRODID:-//CompanyName//ProductName//EN";
  $vcal .= "METHOD:REQUEST";
  $vcal .= "BEGIN:VEVENT";
  $vcal .= "ATTENDEE;CN=\"Attendee1Name\";ROLE=REQ-PARTICIPANT;RSVP=FALSE:MAILTO:Att1Mail@mail.com";
  $vcal .= "ATTENDEE;CN=\"Attendee2Name\";ROLE=REQ-PARTICIPANT;RSVP=FALSE:MAILTO:Att2Mail@mail.com";
  $vcal .= "UID:".date('Ymd').'T'.date('His')."-".rand()."-example.com.my";
  $vcal .= "DTSTAMP:".date('Ymd').'T'.date('His');
  $vcal .= "DTSTART:09/06/2011";
  $vcal .= "DTEND:10/06/2011"; 
  $vcal .= "LOCATION:Meeting room 2";
  $vcal .= "SUMMARY:hahaha....meeting";
  $vcal .= "BEGIN:VALARM";
  $vcal .= "TRIGGER:-PT15M";
  $vcal .= "ACTION:DISPLAY";
  $vcal .= "DESCRIPTION:Reminder";
  $vcal .= "END:VALARM";
  $vcal .= "END:VEVENT";
  $vcal .= "END:VCALENDAR";
 

  $headers .= "\r\nMIME-version: 1.0\r\nContent-Type: text/calendar; method=REQUEST; charset=\"iso-8859-1\"";
  $headers = "From: nybuler\r\nReply-To: nybuler.ong@besta.com.my"; 
  $headers .= "\r\nContent-Transfer-Encoding: 7bit\r\nX-Mailer: Microsoft Office Outlook 12.0"; 

 	//Create the Transport
	$transport = Swift_SmtpTransport::newInstance('mail.example.com.my',25)
      ->setUsername('php.mailer@example.com.my')
      ->setPassword('abc123456');
	
	//Create the Mailer using your created Transport
	$mailer = Swift_Mailer::newInstance($transport);
	
		//Create a message
	$message = Swift_Message::newInstance('Meeting Invite Testing')
	 
	 ->setFrom(array('php.mailer@example.com.my'))
	 ->setTo(array('example@example.com.my')) 
	 //->setTo($to_mail) 
	 //->setCc($cc_mail)
	 //->setBcc($bcc_mail)
	 ->addPart($vcal,'text/calendar');
	//Send the message
    $result = $mailer->send($message);

you can see from here i'm using swift mailer! any one know how to solve my problem?
i'm appreciate for any help!

PS: the email will be send out with an calendar invitation as attachment.
and my problem is i can't open the attachment! God!

Just try the following code and check wheather the calendar opens correctly or not.

header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=calendar.ics");

$vcal = "BEGIN:VCALENDAR";
$vcal .= "VERSION:2.0";
$vcal .= "PRODID:-//CompanyName//ProductName//EN";
$vcal .= "METHOD:REQUEST";
$vcal .= "BEGIN:VEVENT";
$vcal .= "ATTENDEE;CN=\"Attendee1Name\";ROLE=REQ-PARTICIPANT;RSVP=FALSE:MAILTO:Att1Mail@mail.com";
$vcal .= "ATTENDEE;CN=\"Attendee2Name\";ROLE=REQ-PARTICIPANT;RSVP=FALSE:MAILTO:Att2Mail@mail.com";
$vcal .= "UID:".date('Ymd').'T'.date('His')."-".rand()."-besta.com.my";
$vcal .= "DTSTAMP:".date('Ymd').'T'.date('His');
$vcal .= "DTSTART:09/06/2011";
$vcal .= "DTEND:10/06/2011";
$vcal .= "LOCATION:Meeting room 2";
$vcal .= "SUMMARY:hahaha....meeting";
$vcal .= "BEGIN:VALARM";
$vcal .= "TRIGGER:-PT15M";
$vcal .= "ACTION:DISPLAY";
$vcal .= "DESCRIPTION:Reminder";
$vcal .= "END:VALARM";
$vcal .= "END:VEVENT";
$vcal .= "END:VCALENDAR";

echo $val;

exit;

thank for help
but where should i place your code?
you mean i don't send the email but echo it out to see the result 1st?

To Check wheather your calendar is working corect or not before it is attached to mail.

for the header i gain this error

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\eform\accomodation\haha.php:2) in C:\xampp\htdocs\eform\accomodation\haha.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\eform\accomodation\haha.php:2) in C:\xampp\htdocs\eform\accomodation\haha.php on line 6


what does it mean?

do you have suggest link for how to write vcalendar?

Your calendar is not opening. Try ur code with this script.

echo "BEGIN:VCALENDAR\n";
	echo "VERSION:2.0\n";
	echo "PRODID://Foobar Corporation//NONSGML Foobar//EN\n";
	echo "METHOD:PUBLISH\n"; // requied by Outlook
	echo "X-WR-CALNAME:PH2011\n";
	echo "X-WR-TIMEZONE:Asia/Singapore\n";
	echo "BEGIN:VEVENT\n";
	echo "UID:".date('Ymd').'T'.date('His')."-".rand()."-example.com\n"; // required by Outlok
	echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
	echo "DTSTART:Your Date\n"; 
	echo "SUMMARY:Your Summary Here\n";
	echo "LOCATION: Your Location Here\n";
	echo "DESCRIPTION: Your Description Here\n";
	echo "END:VEVENT\n";
	echo "END:VCALENDAR\n";

Hey, I'm thankful for your coding ! It work for the first time
that i have tried 100 times testing T^T thank you!

One more question:

Does it work in Thunderbird?

Sorry :( i dont know about it....

:-/Any way thanks for help:$

Hi, Nybuler Can i get help from you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.