Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Send iCal Email Meeting Requests using PHP Jump to:  
Category: >> PHP Code >> Send iCal Email Meeting Requests using PHP Bookmark and Share

<< lastnext >>

Snippet Name: Send iCal Email Meeting Requests using PHP

Description: Awesome function from Julian Young. Send iCal Email Meeting Requests using PHP! Ensure those buttons show up in Outlook! Tested in Outlook 2003/2007, on Exchange Server 2003 Mailboxes, Google Calendar, Google Mail, Hotmail. includes downloadable source and example usage.
http://www.julian-young.com/2009/07/07/php-ical-email/

Also see:
» Send iCal Email Meeting Requests using...
» Check email address
» Send email with attachments from PL/SQL
» Is email deliverable?
» Email attachments with PHP mail()
» Email w/ attachments class
» Automatically process email
» Live validation of email address
» Send email from Oracle
» Fake email addresses
» Validate email address #3
» Validate email address #2
» Validate email address #1

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?PHP
 
//$firstname is the first name of target
//$lastname is the last name of target
//$email is the targets email address
//$meeting_date is straight from a DATETIME mysql field and assumes UTC.
//$meeting_name is the name of your meeting
//$meeting_duretion is the duration of your meeting in seconds (3600 = 1 hour)
 
FUNCTION sendIcalEmail($firstname,$lastname,$email,$meeting_date,$meeting_name,$meeting_duration) {
 
	$from_name = "My Name";
	$from_address = "myname@mydomain.com";
	$subject = "Meeting Booking"; //Doubles as email subject and meeting subject in calendar
	$meeting_description = "Here is a brief description of my meeting\n\n";
	$meeting_location = "My Office"; //Where will your meeting take place
 
 
	//Convert MYSQL datetime and construct iCal start, end and issue dates
	$meetingstamp = STRTOTIME($meeting_date . " UTC");    
	$dtstart= GMDATE("Ymd\THis\Z",$meetingstamp);
	$dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration);
	$todaystamp = GMDATE("Ymd\THis\Z");
 
	//Create unique identifier
	$cal_uid = DATE('Ymd').'T'.DATE('His')."-".RAND()."@mydomain.com";
 
	//Create Mime Boundry
	$mime_boundary = "----Meeting Booking----".MD5(TIME());
 
	//Create Email Headers
	$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\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 '.$firstname.' '.$lastname.',</p>';
	$message .= '<p>Here is my HTML Email / Used for Meeting Description</p>';    
	$message .= "</body>\n";
	$message .= "</html>\n";
	$message .= "--$mime_boundary\n";
 
	//Create ICAL Content (Google rfc 2445 for details and examples of usage) 
	$ical =    'BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:'.$from_address.'
DTSTART:'.$dtstart.'
DTEND:'.$dtend.'
LOCATION:'.$meeting_location.'
TRANSP:OPAQUE
SEQUENCE:0
UID:'.$cal_uid.'
DTSTAMP:'.$todaystamp.'
DESCRIPTION:'.$meeting_description.'
SUMMARY:'.$subject.'
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR';   
 
	$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
	$message .= "Content-Transfer-Encoding: 8bit\n\n";
	$message .= $ical;            
 
	//SEND MAIL
	$mail_sent = @MAIL( $email, $subject, $message, $headers );
 
	IF($mail_sent)     {
		RETURN TRUE;
	} ELSE {
		RETURN FALSE;
	}   
 
}
 
 
?>
 
 
/////////// example- test.php
 
<?PHP
	INCLUDE ("iCal.php");
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>iCal Test</title>
</head>
 
<body>
<?PHP
 
	//$firstname is the first name of target
	//$lastname is the last name of target
	//$email is the targets email address
	//$meeting_date is straight from a DATETIME mysql field and assumes UTC.
	//$meeting_name is the name of your meeting
	//$meeting_duration is the duration of your meeting in seconds (3600 = 1 hour)
	$firstname = "John";
	$lastname = "Smith";
	$email = "youremail@here.com";
	$meeting_date = "2010-07-06 13:40:00"; //mysql format
	$meeting_name = "Hello";
	$meeting_duration = 3600;
 
	//returns true or false
	$result = sendIcalEmail($firstname,$lastname,$email,$meeting_date,$meeting_name,$meeting_duration);
 
	//display result
	IF($result) {
		ECHO "Email sent successfully.";
	} ELSE {
		ECHO "A problem occurred sending email";
	}   
 
?>
</body>
</html>
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 45 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?