我想将日历邀请发送到电子邮件中。我尝试下面的代码发送讽刺邀请,但它不起作用。
我使用codeigniter Email Libraray发送电子邮件。
创建如下的请求
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@test.com
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:New event
END:VEVENT
END:VCALENDAR";
然后我将此内容添加到:
$this->email->set_header('Content-type', 'text/calendar');
$this->email->attach($ical);
但它不起作用。哪个我错过了或做错了请建议我。
答案 0 :(得分:0)
这是我的emails_model的片段,该片段发送日历事件:
/**
* @param $event
*
* @throws Exception
*/
public function calendar_event($event)
{
$this->load->library('email');
if (empty($event->end_dt))
{
$event->end_dt = clone $event->start_dt;
$event->end_dt->modify('+30 minutes');
}
$location = $event->location ?? '';
$organizer = SITE_NAME;
$organizer_email = Emails_dto::send_from;
$cr = "\n";
/** @var DateTimeZone $tz */
$tz = $event->start_dt->getTimeZone();
$dt = new \DateTime (NULL, new DateTimeZone('UTC'));
$subject = html_entity_decode($event->subject, ENT_QUOTES, 'UTF-8');
$headers = 'From: ' . SITE_NAME . ' <' . Emails_dto::send_from . '>' . $cr;
$headers .= "MIME-Version: 1.0{$cr}";
$headers .= "Content-Type: text/calendar; method=REQUEST;{$cr}";
$headers .= ' charset="UTF-8"' . $cr;
$headers .= 'Content-Transfer-Encoding: 7bit' . $cr;
$message = 'BEGIN:VCALENDAR' . $cr;
$message .= 'PRODID:-//i3SoftWebsite//cal_events/NONSGML v1.0//EN' . $cr;
$message .= 'VERSION:2.0' . $cr;
$message .= 'CALSCALE:GREGORIAN' . $cr;
$message .= 'METHOD:REQUEST' . $cr;
$message .= 'BEGIN:VEVENT' . $cr;
$message .= 'UID:' . md5(uniqid(mt_rand(), TRUE)) . '@' . SITE_DOMAIN_NAME . $cr;
$message .= 'CREATED:' . $dt->format("Ymd\THis") . 'Z' . $cr;
$message .= 'DTSTAMP:' . gmdate('Ymd') . 'T' . gmdate('His') . 'Z' . $cr;
$message .= 'DTSTART;TZID=' . $tz->getName() . ':' . $event->start_dt->format("Ymd\THis") . $cr;
$message .= 'DTEND;TZID=' . $tz->getName() . ':' . $event->end_dt->format("Ymd\THis") . $cr;
$message .= "SUMMARY:{$subject}{$cr}";
$message .= "ORGANIZER;CN={$organizer}:mailto:{$organizer_email}{$cr}";
$message .= "LOCATION:{$location}{$cr}";
$message .= "SEQUENCE:0{$cr}";
$message .= 'DESCRIPTION:' . html_entity_decode($event->description, ENT_QUOTES, 'UTF-8') . $cr;
$recipients = [$event->email_to];
if (empty($event->recipients) === FALSE
&& is_array($event->recipients))
{
foreach ($event->recipients as $recipient)
{
$message .= 'ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=' . $recipient['name'] . ';X-NUM-GUESTS=0:MAILTO:' . $recipient['email'] . $cr;
$recipients[] = $recipient['email'];
}
}
$message .= 'END:VEVENT' . $cr;
$message .= 'END:VCALENDAR' . $cr;
// @codeCoverageIgnoreStart
$email_status = ENVIRONMENT === 'production'
? (int)mail($event->email_to, $subject, $message, $headers)
: 0;
// @codeCoverageIgnoreEnd
$email = new stdClass();
$email->ema_created_dt = $dt->format(DATETIME_MYSQL);
$email->ema_from = $organizer_email;
$email->ema_to = implode(',', $recipients);
$email->ema_subject = $subject;
$email->ema_body = $message;
$email->ema_status = $email_status;
$email->ema_body = substr($headers . $message, 0, 1431655760); // trim this to longtext.
$this->add($email);
}