2

我有使用 php 发送会议邀请的工作代码,对我来说一切正常,电子邮件邀请发送到所有选定的电子邮件地址。但是我面临一个问题,此代码生成的会议邀请未显示在我的日历中,尽管它显示给所有与会者。

这是我的会议邀请功能。

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";
  }

}

请帮助我为什么会议邀请未显示在我的日历中的错误是什么。

4

0 回答 0