Php 通过Symfony2(Swift-Mailer)生成并发送.ics文件
我正在尝试在Symfony2中生成MS Outlook/Google日历事件,而电子邮件是随.ics文件发送的,但我无法将该事件添加到日历中。当我试图打开文件时,它说Php 通过Symfony2(Swift-Mailer)生成并发送.ics文件,php,symfony,icalendar,swiftmailer,Php,Symfony,Icalendar,Swiftmailer,我正在尝试在Symfony2中生成MS Outlook/Google日历事件,而电子邮件是随.ics文件发送的,但我无法将该事件添加到日历中。当我试图打开文件时,它说 Failed to import events: Unable to process your iCal/CSV file.. 这就是我试图生成iCal文件的方式 $message=" BEGIN:VCALENDAR VERSION:2.0 CALSCALE:GREGORIAN METHOD:RE
Failed to import events: Unable to process your iCal/CSV file..
这就是我试图生成iCal文件的方式
$message="
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:".date('Ymd\THis', strtotime($meetingStartTime))."
DTEND:".date('Ymd\THis', strtotime($meetingEndTime))."
DTSTAMP:".date('Ymd\THis', strtotime($meetingStartTime))."
ORGANIZER;CN=XYZ:mailto:do-not-reply@example.com
UID:".rand(5, 1500)."
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Sample:emailaddress@testemail.com
DESCRIPTION:".$this->getUser()->getName()." requested Phone/Video Meeting Request
LOCATION: Phone/Video
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Meeting has been scheduled by ".$this->getUser()->getName()."
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR";
$messageObject = \Swift_Message::newInstance();
$messageObject->setContentType("text/calendar");
$messageObject->setSubject("Your meeting has been booked")
->setFrom($this->container->getParameter('mailer_user'), "From Name")
->setTo($this->getUser()->getEmail())
->setBody(trim($message));
$this->get('mailer')->send($messageObject);
如果我能就导致导入事件失败的问题获得一些帮助,我将不胜感激:无法处理您的iCal/CSV文件您应该在服务器上编写iCal文件(使用或使用本机PHP函数,如),然后将其作为附件发送:
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
$fs = new Filesystem();
//temporary folder, it has to be writable
$tmpFolder = '/tmp/';
//the name of your file to attach
$fileName = 'meeting.ics';
$icsContent = "
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:".date('Ymd\THis', strtotime($meetingStartTime))."
DTEND:".date('Ymd\THis', strtotime($meetingEndTime))."
DTSTAMP:".date('Ymd\THis', strtotime($meetingStartTime))."
ORGANIZER;CN=XYZ:mailto:do-not-reply@example.com
UID:".rand(5, 1500)."
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Sample:emailaddress@testemail.com
DESCRIPTION:".$this->getUser()->getName()." requested Phone/Video Meeting Request
LOCATION: Phone/Video
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Meeting has been scheduled by ".$this->getUser()->getName()."
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR"
;
//creation of the file on the server
$icfFile = $fs->dumpFile($tmpFolder.$fileName, $icsContent);
//message to include as body to your mail
$body = 'Hello...';
$messageObject = \Swift_Message::newInstance();
$messageObject->setSubject("Your meeting has been booked")
->setFrom($this->container->getParameter('mailer_user'), "From Name")
->setTo($this->getUser()->getEmail())
->setBody($body)
->attach(Swift_Attachment::fromPath($tmpFolder.$fileName))
;
$this->get('mailer')->send($messageObject);
//remove the created file
$fs->remove(array('file', $tmpFolder, $fileName));
您应该改为在服务器上编写iCal文件(使用或使用本机PHP函数,如),然后将其作为附件发送:
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
$fs = new Filesystem();
//temporary folder, it has to be writable
$tmpFolder = '/tmp/';
//the name of your file to attach
$fileName = 'meeting.ics';
$icsContent = "
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:".date('Ymd\THis', strtotime($meetingStartTime))."
DTEND:".date('Ymd\THis', strtotime($meetingEndTime))."
DTSTAMP:".date('Ymd\THis', strtotime($meetingStartTime))."
ORGANIZER;CN=XYZ:mailto:do-not-reply@example.com
UID:".rand(5, 1500)."
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Sample:emailaddress@testemail.com
DESCRIPTION:".$this->getUser()->getName()." requested Phone/Video Meeting Request
LOCATION: Phone/Video
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Meeting has been scheduled by ".$this->getUser()->getName()."
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR"
;
//creation of the file on the server
$icfFile = $fs->dumpFile($tmpFolder.$fileName, $icsContent);
//message to include as body to your mail
$body = 'Hello...';
$messageObject = \Swift_Message::newInstance();
$messageObject->setSubject("Your meeting has been booked")
->setFrom($this->container->getParameter('mailer_user'), "From Name")
->setTo($this->getUser()->getEmail())
->setBody($body)
->attach(Swift_Attachment::fromPath($tmpFolder.$fileName))
;
$this->get('mailer')->send($messageObject);
//remove the created file
$fs->remove(array('file', $tmpFolder, $fileName));
如果要创建OOP,可以使用以下软件包:
可以使用composer完成安装,并且无需为SF用户在appKernel中添加捆绑包。如果需要创建OOP,可以使用以下软件包:
安装可以使用composer完成,无需为SF用户在appKernel中添加捆绑包。为什么不在服务器上编写ics文件,然后将其作为附件发送?@Veve您能给我举个例子吗?因为这对很多人都有帮助,为什么不在服务器上编写ics文件,然后作为附件发送呢?@Veve你能给我举个例子吗?因为它真的会帮助LOT,有人知道这样的ICS文件的OOP创建库吗?你和那个包有关系吗?它似乎没有作曲家的支持。无论如何,谢谢你。不要再劫持这个线程了。很抱歉离开主题。@mblaettermann完全没有关联,只是我在搜索过程中找到的一个结果。有人知道这样的ICS文件的OOP创建库吗?你与该包有关联吗?它似乎没有作曲家的支持。无论如何,谢谢你。不要再劫持这个线程了。很抱歉离开主题。@mblaettermann完全没有关联,只是我在搜索过程中找到的结果之一。请说明与包的关联:)请说明与包的关联:)