PHPMailer将日历事件发送到Outlook邮件

7jmck4yq  于 2023-02-28  发布在  PHP
关注(0)|答案(2)|浏览(149)

我知道有很多关于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作为附件发送

4xrmg8kj

4xrmg8kj1#

问题是Gmail处理日历不正确--它只是坏了。
如果你想让它们同时在Gmail和Outlook中工作,你需要将日历项作为text/calendar邮件的一部分和附件一起添加。这是非常愚蠢的,但这是当电子邮件客户端开发人员不阅读标准时发生的事情,这对gmail来说几乎是例行公事,因为它在许多其他方面也是坏的。
你不能通过添加随机头来蒙混过关;你试过的那些很可能会把东西弄坏。
an open ticket for this in PHPMailer有更多的细节,但它不太可能很快得到解决。

bq3bfh9z

bq3bfh9z2#

唯一的方法,我得到这个工作在Gmail,Office 365,MS Outlook,Zoho邮件和iPhone邮件应用程序是通过在MS Outlook中创建和约会,下载存档,用VS代码这样的文本编辑器打开它,并将其粘贴在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');

相关问题