我知道有很多关于PHPMailer的问题,我试了大部分,但仍然没有运气,
我需要发送日历事件到Gmail & Outlook,我已经实现了Gmail与下面的脚本,但对于Outlook的ics文件已作为附件发送,而不是作为一个日历事件。
$mail = new PHPMailer();
$mail->Host = "smtp.mandrillapp.com";
$mail->Username = SMTP_EMAIL; // defined as constant
$mail->Password = SMTP_PASSWORD; // defined as constant
$mail->Port = 587;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPDebug = 0;
$mail->isHTML(FALSE);
$mail->setFrom('k***@gmail.com', 'name');
$mail->addReplyTo('k***@gmail.com', 'name');
$mail->addAddress('v***@gmail.com', 'Gmail'); // to gmail
$mail->addAddress('k***@outlook.com','Outlook'); // to outlook
$mail->ContentType = 'text/calendar';
$ical = "BEGIN:VCALENDAR\r\n";
$ical .= "VERSION:2.0\r\n";
$ical .= "PRODID:-//LothCalendar//ATMRequest//EN\r\n";
$ical .= "METHOD:REQUEST\r\n";
$ical .= "BEGIN:VEVENT\r\n";
$ical .= "ORGANIZER;SENT-BY=\"MAILTO:k***@gmail.com\":MAILTO:ke***@outlook.com\r\n";
$ical .= "UID:".strtoupper(md5($event_id))."-lothcalendar.local\r\n";
// $ical .= "ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=k***@outlook.com;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE:mailto:k***@gmail.com\r\n";
$ical .= "ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Namekeviveks:mailto:k***@gmail.com\r\n";
$ical .= "SEQUENCE:".$sequence."\r\n";
$ical .= "STATUS:".$status."\r\n";
$ical .= "DTSTAMPTZID=Asia/Calcutta:".date('Ymd').'T'.date('His')."\r\n";
$ical .= "DTSTART:".$start."T".$start_time."\r\n";
$ical .= "DTEND:".$end."T".$end_time."\r\n";
$ical .= "LOCATION:".$venue."\r\n";
$ical .= "SUMMARY:".$summary."\r\n";
$ical .= "DESCRIPTION:some sample event description\r\n";
$ical .= "BEGIN:VALARM\r\n";
$ical .= "TRIGGER:-PT15M\r\n";
$ical .= "ACTION:DISPLAY\r\n";
$ical .= "DESCRIPTION:Reminder\r\n";
$ical .= "END:VALARM\r\n";
$ical .= "END:VEVENT\r\n";
$ical .= "END:VCALENDAR\r\n";
$mail->Subject = "Invitation: Outlook Calendar Event";
$mail->AddStringAttachment($ical, "event.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST");
$mail->Body = "Test Outlook Calendar event mail";
$mail->Ical = $ical;
//send the message, check for errors
if(!$mail->send()) {
return false;
} else {
return true;
}
我已经试过了
1.自定义标题
$mail->addCustomHeader('MIME-version',"1.0");
$mail->addCustomHeader('Content-type',"text/calendar; name=event.ics; method=REQUEST; charset=UTF-8;");
$mail->addCustomHeader('Content-type',"text/html; charset=UTF-8");
$mail->addCustomHeader('Content-Transfer-Encoding',"7bit");
$mail->addCustomHeader('X-Mailer',"Microsoft Office Outlook 12.0");
$mail->addCustomHeader("Content-class: urn:content-classes:calendarmessage");
无法在Gmail和Outlook中使用(邮件作为ICS内容的普通文本发送)
2.简易豌豆智能卡
$invite = new EasyPeasyICS();
$invite->addEvent('06-06-2016 08:00:00','06-06-2016 17:00:00',"TEST","TEST","");
$mail->Ical = $invite->render(false);
无法在Gmail和Outlook中使用(邮件作为ICS内容的普通文本发送)
3.添加字符串附件
$mail->AddStringAttachment($ical, "event.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST");
在gmail中工作,但在outlook中将event.ics作为附件发送
2条答案
按热度按时间4xrmg8kj1#
问题是Gmail处理日历不正确--它只是坏了。
如果你想让它们同时在Gmail和Outlook中工作,你需要将日历项作为
text/calendar
邮件的一部分和附件一起添加。这是非常愚蠢的,但这是当电子邮件客户端开发人员不阅读标准时发生的事情,这对gmail来说几乎是例行公事,因为它在许多其他方面也是坏的。你不能通过添加随机头来蒙混过关;你试过的那些很可能会把东西弄坏。
an open ticket for this in PHPMailer有更多的细节,但它不太可能很快得到解决。
bq3bfh9z2#
唯一的方法,我得到这个工作在Gmail,Office 365,MS Outlook,Zoho邮件和iPhone邮件应用程序是通过在MS Outlook中创建和约会,下载存档,用VS代码这样的文本编辑器打开它,并将其粘贴在StringAttachment中,没有easypeasyics,像这样的东西: