我想使用用户输入到我的 ContactForm7 表单来构建一个 ICS 文件链接,然后将此 ICS 文件链接包含在表单的电子邮件输出到我的收件箱中。
注意:一个 ICS 文件是一个链接,可以被 Outlook、Google 日历、Apple 日历等读取...
// build an ICS file using this class
class ICS {
var $data;
var $name;
function ICS($start,$end,$name,$description,$location) {
$this->name = $name;
$this->data = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTART:".date("Ymd\THis\Z",strtotime($start))."\nDTEND:".date("Ymd\THis\Z",strtotime($end))."\nLOC\
ATION:".$location."\nTRANSP: OPAQUE\nSEQUENCE:0\nUID:\nDTSTAMP:".date("Ymd\THis\Z")."\nSUMMARY:".$name."\nDESCRIPTION:".$description."\nPRIORITY:1\nCLASS:PUBLIC\nBEGIN:VALARM\nTRIGGE\
R:-PT10080M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR\n";
}
function save() {
file_put_contents($this->name.".ics",$this->data);
}
function show() {
return $this->data;
}
}
// add action before_send_mail
add_action( 'wpcf7_before_send_mail', 'before_send_mail' );
// build the ICS file here and include it in the email to my inbox
function before_send_mail( $wpcf7 ) {
private $ics_link;
// call the ICS class instance
$event = new ICS("2023-03-30 16:00","2023-03-30 17:00","Test Event","This an event made to test","GU1 1AA");
// Add the ICS file string
$ics_link = $event->show();
// CAPTURE INSTANCE OF WPCFY CLASS AND ADD ICS FILE LINK TO EMAIL BODY
}
NNB:我从这个 StackOverflow 页面获得了大部分 ICS 文件类..