Meeting Invite doesn't show up in my Calendar

178 Views Asked by At

I have working Code for sending meetings invites using php, every thing working fine for me, email invite send to all selected email addresses. But i face one issue, meeting invite generated by this code, doesn't show up in my calendar, although it show up to all attendees.

Here is my Function for meeting Invite.

function send_calendar_invite ($to,$str_cc,$str_bcc,$subject,$body,$from_addr,$from_name,$from_password,$meeting_date,$meeting_duration,$meeting_location)
{

  if($str_cc!='')
  {
    $cc_addr=explode(",",$str_cc);
    $cc_cnt=count($cc_addr);
  }

  if($str_bcc!='')
  {
    $bcc_addr=explode(",",$str_bcc);
    $bcc_cnt=count($bcc_addr);
  }

  $to_addr = explode(",",$to);
  $to_cnt=count($to_addr);


  //Convert MYSQL datetime and construct iCal start, end and issue dates
  $meetingstamp = strtotime($meeting_date. " UTC");    
  $dtstart= gmdate("Ymd\THis",$meetingstamp);
  $dtend= gmdate("Ymd\THis",$meetingstamp+$meeting_duration);
  $todaystamp = gmdate("Ymd\THis");
  
  //Create unique identifier
  $cal_uid = date('Ymd').'T'.date('His')."-".rand()."@outlook.com";

  //Create Email Headers
  $headers = "From: ".$from_name." <".$from_addr.">\n";
  $headers .= "Reply-To: ".$from_name." <".$from_addr.">\n";


  //Create Email Body (HTML)
  $message = '';
  $message .= "<html>\n";
  $message .= "<body>\n";
  $message .= '<p>Hi All,</p>';
  $message .= $body;    
  $message .= "</body>\n";
  $message .= "</html>\n";
  
  
  //Create ICAL Content (Google rfc 2445 for details and examples of usage) 
  $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 Standard Time' . "\r\n" .
  'BEGIN:STANDARD' . "\r\n" .
  'DTSTART:16011104T020000' . "\r\n" .
  'RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11' . "\r\n" .
  'TZOFFSETFROM:-0400' . "\r\n" .
  'TZOFFSETTO:-0500' . "\r\n" .
  'TZNAME:Eastern Standard Time' . "\r\n" .
  'END:STANDARD' . "\r\n" .
  'BEGIN:DAYLIGHT' . "\r\n" .
  'DTSTART:16010311T020000' . "\r\n" .
  'RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3' . "\r\n" .
  'TZOFFSETFROM:-0500' . "\r\n" .
  'TZOFFSETTO:-0400' . "\r\n" .
  'TZNAME:Eastern Standard Time' . "\r\n" .
  'END:DAYLIGHT' . "\r\n" .
  'END:VTIMEZONE' . "\r\n" .  
  'BEGIN:VEVENT' . "\r\n" .
  'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_addr. "\r\n";
  for($i=0;$i<$to_cnt;$i++)
  {
      $ical .='ATTENDEE;CN="'.$to_addr[$i].'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_addr[$i]. "\r\n";
  }
  $ical .='LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
  'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."@outlook.com \r\n" .
  'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
  'DTSTART;TZID="Eastern Standard Time":'.$dtstart. "\r\n" .
  'DTEND;TZID="Eastern Standard Time":'.$dtend. "\r\n" .
  'TRANSP:OPAQUE'. "\r\n" .
  'SEQUENCE:1'. "\r\n" .
  'SUMMARY:' . $subject . "\r\n" .
  'LOCATION:' . $meeting_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";



  $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
  try {
      //Server settings
     //$mail->SMTPDebug = 2;                                 // Enable verbose debug output
      $mail->isSMTP();                                      // Set mailer to use SMTP
      $mail->Host = 'smtp.office365.com';  // Specify main and backup SMTP servers
      $mail->SMTPAuth = true;                               // Enable SMTP authentication
      $mail->Username = $from_addr;                 // SMTP username
      $mail->Password = $from_password;                           // SMTP password
      $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
      $mail->Port = 587;                                    // TCP port to connect to
      //Recipients
      $mail->setFrom($from_addr, $from_name);
      for($i=0;$i<$to_cnt;$i++)
      {
        $mail->addAddress(trim($to_addr[$i]));
      }
      
    
    $mail->addReplyTo($from_addr, $from_name);

    if($cc_cnt>=0)
    {
      for($i=0;$i<$cc_cnt;$i++)
      {
        //echo $cc_addr[$i] . "test";
        $mail->addCC(trim($cc_addr[$i]));
      }
    }

    if($bcc_cnt>=0)
    {
      for($i=0;$i<$bcc_cnt;$i++)
      {
        $mail->addBCC(trim($bcc_addr[$i]));
      }
    }
  

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body    = $message;
    $mail->AltBody = $message;
    $mail->AddStringAttachment("$ical", "meeting.ics", "base64", "text/calendar; charset=utf-8; method=REQUEST");

    $mail->send();
    //echo 'Message has been sent';
    return "sent";
  } catch (Exception $e) {
      //echo 'Message could not be sent.';
      //echo 'Mailer Error: ' . $mail->ErrorInfo;
    return "failed";
  }

}

Please help me what is the the error why meeting invite isn't showing up in my calendar.

0

There are 0 best solutions below