我知道有很多与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。 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);
在Gmail和Outlook中均无法使用(邮件作为ICS内容的普通文本发送)
第3。 AddStringAttachment
$mail->AddStringAttachment($ical, "event.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST");
适用于Gmail,但在outlook 中将event.ics作为附件发送
答案 0 :(得分:0)
问题是Gmail无法正确处理日历 - 它只是破碎了。
如果您希望它们同时在Gmail和Outlook中使用,则需要将日历项目作为text/calendar
消息和中的multipart/alternative
部分添加为附件。这是非常愚蠢的,但是当电子邮件客户端开发人员没有阅读标准时会发生什么,这对gmail来说几乎和往常一样,因为它在许多其他方面也被打破了。
你可以通过添加随机标题来捏造这个;你尝试过的那些可能会非常糟糕。
an open ticket for this in PHPMailer有更详细的信息,但不太可能很快得到解决。
答案 1 :(得分:0)
我要在Gmail,Office 365,MS Outlook,Zoho邮件和iPhone Mail App中使用此方法的唯一方法是在MS Outlook中创建并进行约会,下载档案,然后使用VS Code这样的文本编辑器将其打开并粘贴它在StringAttachment中,没有easypeasyics,就像这样:
$ical_content = 'BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VTIMEZONE
TZID:SA Pacific Standard Time
BEGIN:STANDARD
DTSTART:16010101T000000
TZOFFSETFROM:-0500
TZOFFSETTO:-0500
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:20191203T124654Z
DESCRIPTION:Cumbre LATAM 2019\n
DTEND;TZID="SA Pacific Standard Time":20191210T220000
DTSTAMP:20191203T124654Z
DTSTART;TZID="SA Pacific Standard Time":20191210T150000
LAST-MODIFIED:20191203T124654Z
LOCATION:The Westin Lima Hotel & Convention Center
PRIORITY:5
SEQUENCE:0
SUMMARY;LANGUAGE=es:Event
TRANSP:OPAQUE
UID:040000008200E00074C5B7101A82E00800000000A06260CDADA9D501000000000000000
010000000FC95C5664F74B04B8AEB1601B7F04AD6
X-ALT-DESC;FMTTYPE=text/html:<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-mic
rosoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/
<!---- THERE IS A BUNCH OF CODE THAT OUTLOOK GENERATE HERE BUT IT OVERFLOWS THE ANSWER CAPACITY, BUT WITHOUT IT, THE APPOINTMENT DOESN'T WORK ----->
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MS-OLK-AUTOFILLLOCATION:FALSE
X-MS-OLK-CONFTYPE:0
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR';
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8'; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specicfy main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;
$mail->setFrom('no-reply@appointment.pe', '');
$mail->addAddress($data['email'], $data['name']);
$mail->addReplyTo('no-reply@appointment.pe', '');
$mail->isHTML(true);
$mail->Subject = $data['subject'];
$mail->MsgHTML($data['body']);
$mail->addStringAttachment($ical_content,'ical.ics','base64','text/calendar');