加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:28:25 所属栏目:PHP教程 来源:网络整理
导读:我想将日历邀请发送到电子邮件中.我尝试下面的代码发送ical邀请但它不起作用. 我正在使用codeigniter Email Libraray发送电子邮件. 创建如下的ical请求 $ical = "BEGIN:VCALENDARVERSION:2.0PRODID:-//hacksw/handcal//NONSGML v1.0//ENBEGIN:VEVENTUID:" .
我想将日历邀请发送到电子邮件中.我尝试下面的代码发送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("YmdTHis") . 'Z' . $cr;
  $message    .= 'DTSTAMP:' . gmdate('Ymd') . 'T' . gmdate('His') . 'Z' . $cr;
  $message    .= 'DTSTART;TZID=' . $tz->getName() . ':' . $event->start_dt->format("YmdTHis") . $cr;
  $message    .= 'DTEND;TZID=' . $tz->getName() . ':' . $event->end_dt->format("YmdTHis") . $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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读