我知道有许多与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. Custom Headers
$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");
not worked in both Gmail and Outlook (mail send as normal text of ICS content)
2. EasyPeasyICS
$invite = new EasyPeasyICS();
$invite->addEvent('06-06-2016 08:00:00','06-06-2016 17:00:00',"TEST","TEST","");
$mail->Ical = $invite->render(false);
not worked in both Gmail and Outlook (mail send as normal text of ICS content)
3. AddStringAttachment
$mail->AddStringAttachment($ical, "event.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST");
works in gmail but sending event.ics as attachment in outlook