微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 使用codeigniter电子邮件库在电子邮件上发送邀请

我想将日历邀请发送到电子邮件中.我尝试下面的代码发送ical邀请但它不起作用.

我正在使用codeigniter Email Libraray发送电子邮件.

创建如下的ical请求

$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);

但它没有用.哪个我错过了或做错了请建议我.

我试图在电子邮件中得到低于结果

enter image description here

解决方法

这是我发送日历事件的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,'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,1431655760); // trim this to longtext.
  $this->add($email);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐