2

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.

  • Quick fix maybe add yourself as an attendee also? That is, should the organizer also be an attendee. – ficuscr Sep 28 '20 at 06:09
  • Does this answer your question? [iCal not showing meeting time slot for organizer](https://stackoverflow.com/questions/52364578/ical-not-showing-meeting-time-slot-for-organizer) Think I guessed it. Recall the specs on vcal stuff was always spotty to non existent. – ficuscr Sep 28 '20 at 06:10
  • I have also added my-self as attendee, but it still didn't show time slot in my calendar. – Zeeshan Zulfiqar Sep 28 '20 at 07:04
  • Voted to reopen. Is it just something with your calendar? Test on other machine or something? – ficuscr Sep 28 '20 at 07:23
  • I think something i am missing in my code, i don't know what is it. i have tried with 3 different outlook accounts. but i cant get the time slot in my calendar. – Zeeshan Zulfiqar Sep 28 '20 at 07:30
  • Does you being an attendee but not an organizer let you add it to your calendar? Trying to verify the same thing still. – ficuscr Sep 28 '20 at 07:34
  • Sorry i can't get, what you are saying – Zeeshan Zulfiqar Sep 28 '20 at 07:37
  • So, you say it works for the attendees. If you create an invite, where you are *not* an organizer but just an attendee, can *you* then get it to add to your calendar? – ficuscr Sep 28 '20 at 07:38
  • Seen this one? https://stackoverflow.com/questions/61618410/ical-event-not-added-into-organizer-calendar – ficuscr Sep 28 '20 at 07:41
  • Yes, if i use my web@xyz.com account and insert myname@xyz.com as attendee. myname@xyz.com will get invite and also showed up in calendar. but web@xyz.com calendar will be empty no timeslot for organizer and also organizer cant edit or reschedule meeting – Zeeshan Zulfiqar Sep 28 '20 at 07:42
  • **Seen this one? stackoverflow.com/questions/61618410/… – ficuscr 1 hour ago** this isnt the working for me – Zeeshan Zulfiqar Sep 28 '20 at 09:38

0 Answers0