PHP-скрипт для очистки писем о встречах и создания файла .ics для отправки по электронной почте соответствующему пользователю для упрощения планирования

Я работаю в бизнесе, где у нас есть размещенная CRM, которая рассылает рабочие листы, которые мы пытаемся закодировать в php скрипт, который отправляет нам по электронной почте записи календаря для заданий, назначенных нам в настоящее время, код (ниже) очищает нашу электронную почту и отправляет нам сообщения .ics, но он выводится, в то время как действительный файл .ics (мы можем импортировать их вручную) не появляется в электронном письме как приемлемое приглашение, поэтому мы можем просто принять запись Advice & по достоинству оценил

—Оригинальный код—

$mbox=FALSE;
$imap_username="[email protected]";
$imap_password="Password";

$connection="{".$server.":".$port."}".$path;
$mbox=imap_open($connection, $imap_username, $imap_password);
$messages=imap_search($mbox, 'UNSEEN SUBJECT "Commtrak: Job Card"');
foreach($messages as $message){
//var_dump(imap_header($mbox,$message));
$bodynormal = imap_body($mbox,$message);
$body = str_replace(" "," ",strip_tags($bodynormal));

$to = $imap_username;
$subjectsearch = array("Company Name:","Job ID:");
$subject = locatedata($body,"Company Name:","Job ID:");

$organizer = 'CommTrak';
$organizer_email = '[email protected]';

$participant_name_1 = 'User';
$participant_email_1= $imap_username;
if(strpos($body,"Sales Contact:")!=false){
$search = "Sales Contact:";
}
else{
$search = "Customer Contact:";
}
if(locatedata($body,"Site Address:",$search)=="As Above"){
$location = locatedata($body,"Customer Address:","Site Address:");
}
else{
$location = locatedata($body,"Site Address:",$search);
}
$date = "20".implode('', array_reverse(explode("/",locatedata($body,"Date:","Time:"))));
$startTime = locatedata($body,"Time:","For:");
$endTime = date("H:i",strtotime($startTime." +".str_replace("hrs","hours",locatedata($body,"For:","JOB DESCRIPTION:"))));
$startTime = str_replace(":","",$startTime);
$endTime = str_replace(":","",$endTime);
$desc = locatedata($body,"JOB DESCRIPTION:","CO Number:");
$headers = "From: CommTrak Jobs <[email protected]>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/calendar; charset=utf-8; name=jobcard.ics; method=REQUEST\r\n";
$headers .= "Content-Disposition: inline; filename='jobcard.ics'\r\n";
//$headers .= "Content-class','urn:content-classes:calendarmessage";
$headers .= "Content-Transfer-Encoding: base64";

$message = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft Exchange Server 2010\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:Tasmania Standard Time\r\nBEGIN:STANDARD\r\nDTSTART:16010101T030000\r\nTZOFFSETFROM:+1100\r\nTZOFFSETTO:+1000\r\nRRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=4\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:+1000\r\nTZOFFSETTO:+1100\r\nRRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=10\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nORGANIZER;CN=".$organizer.":mailto:".$organizer_email."\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=".$participant_name_1.":MAILTO:".$participant_email_1."\r\nDESCRIPTION;LANGUAGE=en-US:".$desc."\r\nUID:".md5(uniqid(mt_rand(),true))."tbclaunceston.com.au\r\nSUMMARY;LANGUAGE=en-US:".$subject."\r\nDTSTART;TZID='Tasmania Standard Time':".$date."T".$startTime."00\r\nDTEND;TZID='Tasmania Standard Time':".$date."T".$endTime."00\r\nCLASS:PUBLIC\r\nPRIORITY:5\r\nDTSTAMP:".gmdate('Ymd').'T'.gmdate('His')."Z\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nSEQUENCE:0\r\nLOCATION;LANGUAGE=en-US:".$location."\r\nX-MICROSOFT-CDO-APPT-SEQUENCE:0\r\nX-MICROSOFT-CDO-OWNERAPPTID:1787906015\r\nX-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-DISALLOW-COUNTER:FALSE\r\nBEGIN:VALARM\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT15M\r\nACTION:DISPLAY\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
//$headers .= $message;
$message = base64_encode($message);
mail($to, $subject, $message, $headers);
break;
//echo $message."\r\n***********************\r\n";
}
?>

—Текущая итерация кода

$connection="{".$server.":".$port."}".$path;
$mbox=imap_open($connection, $imap_username, $imap_password);
$messages=imap_search($mbox, 'UNSEEN SUBJECT "Commtrak: Job Card"');
foreach($messages as $message){
//var_dump(imap_header($mbox,$message));
$boundary=uniqid("np");
$bodynormal = imap_body($mbox,$message);
$body = str_replace("&nbsp;"," ",strip_tags($bodynormal));

//$to = $imap_username;
$to = "[email protected]";
$subjectsearch = array("Company Name:","Job ID:");
$subject = locatedata($body,"Company Name:","Job ID:");

$organizer = 'CommTrak';
$organizer_email = '[email protected]';

$participant_name_1 = 'a User';
$participant_email_1= $imap_username;
if(strpos($body,"Sales Contact:")!=false){
$search = "Sales Contact:";
}
else{
$search = "Customer Contact:";
}
if(locatedata($body,"Site Address:",$search)=="As Above"){
$location = locatedata($body,"Customer Address:","Site Address:");
}
else{
$location = locatedata($body,"Site Address:",$search);
}
$date = "20".implode('', array_reverse(explode("/",locatedata($body,"Date:","Time:"))));
$startTime = locatedata($body,"Time:","For:");
$endTime = date("H:i",strtotime($startTime." +".str_replace("hrs","hours",locatedata($body,"For:","JOB DESCRIPTION:"))));
$startTime = str_replace(":","",$startTime);
$endTime = str_replace(":","",$endTime);
$desc = locatedata($body,"JOB DESCRIPTION:","CO Number:");
$headers = "From: CommTrak Jobs <[email protected]>\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "To:".$to."\r\n";
$headers .= "Content-type:multipart/alternative;boundary=".$boundary."\r\n\r\n--".$boundary."\r\n";
$headers .= "Content-Type: text/calendar; charset=utf-8; name=jobcard.ics; method=REQUEST\r\n";
$headers .= "Content-Disposition: inline; filename='jobcard.ics'\r\n";
//$headers .= "Content-class','urn:content-classes:calendarmessage";
$headers .= "Content-Transfer-Encoding: base64;
//boundary=".$boundary."\r\n";

$message = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft Exchange Server 2010\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:Tasmania Standard Time\r\nBEGIN:STANDARD\r\nDTSTART:16010101T030000\r\nTZOFFSETFROM:+1100\r\nTZOFFSETTO:+1000\r\nRRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=4\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:+1000\r\nTZOFFSETTO:+1100\r\nRRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=10\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nORGANIZER;CN=".$organizer.":mailto:".$organizer_email."\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=".$participant_name_1.":MAILTO:".$participant_email_1."\r\nDESCRIPTION;LANGUAGE=en-US:".$desc."\r\nUID:".md5(uniqid(mt_rand(),true))."tbclaunceston.com.au\r\nSUMMARY;LANGUAGE=en-US:".$subject."\r\nDTSTART;TZID='Tasmania Standard Time':".$date."T".$startTime."00\r\nDTEND;TZID='Tasmania Standard Time':".$date."T".$endTime."00\r\nCLASS:PUBLIC\r\nPRIORITY:5\r\nDTSTAMP:".gmdate('Ymd').'T'.gmdate('His')."Z\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nSEQUENCE:0\r\nLOCATION;LANGUAGE=en-US:".$location."\r\nX-MICROSOFT-CDO-APPT-SEQUENCE:0\r\nX-MICROSOFT-CDO-OWNERAPPTID:1787906015\r\nX-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-DISALLOW-COUNTER:FALSE\r\nBEGIN:VALARM\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT15M\r\nACTION:DISPLAY\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
//$message = base64_encode($message);
$message .= "\r\n\r\n--".$boundary."\r\n";
mail($to, $subject, $message, $headers);
break;
//echo $message."\r\n***********************\r\n";
}
?>

—Результирующий вывод сообщения

Delivered-To: [email protected]
Received: by 10.140.163.3 with SMTP id j3csp923632qhj;
Tue, 21 Apr 2015 17:26:48 -0700 (PDT)
X-Received: by 10.68.111.35 with SMTP id if3mr38633671pbb.70.1429662408016;
Tue, 21 Apr 2015 17:26:48 -0700 (PDT)
Return-Path: <[email protected]>
Received: from tclp-28.localdomain (totalc92.lnk.telstra.net. [120.151.44.165])
by mx.google.com with ESMTP id u7si5131112pbs.1.2015.04.21.17.26.47
for <[email protected]>;
Tue, 21 Apr 2015 17:26:47 -0700 (PDT)
Received-SPF: none (google.com: [email protected] does not designate permitted sender hosts) client-ip=120.151.44.165;
Authentication-Results: mx.google.com;
spf=none (google.com: [email protected] does not designate permitted sender hosts) [email protected]
Received: by tclp-28.localdomain (Postfix, from userid 0)
id 8C7EED40968; Wed, 22 Apr 2015 10:26:45 +1000 (AEST)
To: [email protected]
Subject: ROBERT FINDLAY
X-PHP-Originating-Script: 1000:ICSconverter3.php
From: CommTrak Jobs <[email protected]>
MIME-Version: 1.0
To:[email protected]
Content-type:multipart/alternative;boundary=np5536eac52d6fe
Message-Id: <[email protected]>
Date: Wed, 22 Apr 2015 10:26:45 +1000 (AEST)

--np5536eac52d6fe
Content-Type: text/calendar; charset=utf-8; name=jobcard.ics; method=REQUEST
Content-Disposition: inline; filename='jobcard.ics'
Content-Transfer-Encoding: base64;
//boundary=np5536eac52d6fe

BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:Microsoft Exchange Server 2010
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Tasmania Standard Time
BEGIN:STANDARD
DTSTART:16010101T030000
TZOFFSETFROM:+1100
TZOFFSETTO:+1000
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=4
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:+1000
TZOFFSETTO:+1100
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=10
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ORGANIZER;CN=CommTrak:mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=a User:MAILTO:[email protected]
DESCRIPTION;LANGUAGE=en-US:On site set-up for office 365. installing accounts/products on devices
UID:c1cb622dd0d1ecdc9e93f778d0b7964atbclaunceston.com.au
SUMMARY;LANGUAGE=en-US:Agent Smith
DTSTART;TZID='Tasmania Standard Time':20150424T-00
DTEND;TZID='Tasmania Standard Time':20150424T100000
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20150422T002645Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION;LANGUAGE=en-US:123 some where RD
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-OWNERAPPTID:1787906015
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-DISALLOW-COUNTER:FALSE
BEGIN:VALARM
DESCRIPTION:REMINDER
TRIGGER;RELATED=START:-PT15M
ACTION:DISPLAY
END:VALARM
END:VEVENT
END:VCALENDAR--np5536eac52d6fe

0

Решение

Ну, у вас есть составная часть / альтернатива, содержащая только часть текста / календаря, которая в порядке, но не очень полезна.
Тогда у вас есть кодировка передачи контента, когда на самом деле ваша часть тела не кодируется b64.
У вас также есть эта странная строка комментария после последнего заголовка («// border = np5536eac52d6fe»).

Наконец, ваш DTSTART недействителен: «20150424T-00»

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]