简体   繁体   中英

Sending an i calendar as mail body in php mailer

I am using php mailer to send mails to recipients and I need to send i calendar events, i know how to send them as an attachment but i want to send them in mail body. is it possible?

$message = "You have been invited to the online meeting '".$schedule->schedule_name.
                                    "', On ".$date." (".$start_time."-".$end_time.") by Tuti.World \n
                                    (See attachments for more details)";

        $ical_content = "BEGIN:VCALENDAR
                                        VERSION:2.0
                                        PRODID://Drupal iCal API//EN
                                        BEGIN:VEVENT
                                        UID:http://www.icalmaker.com/event/d8fefcc9-a576-4432-8b20-40e90889affd
                                        DTSTAMP:".$date.
                                        "DTSTART:".$start_time.
                                        "DTEND:".$end_time.
                                        "SUMMARY:Online Meeting
                                        END:VEVENT
                                        END:VCALENDAR";



$mail->msgHTML($message);
$mail->addStringAttachment($ical_content,$file,'base64','text/calendar');
$mail->send();

these are the code blocks of the current mail body and calendar event...

PHPMailer has built-in iCal support, which it uses to create a third text/calendar part within a multipart/alternative structure. This is "the RFC way", but unfortunately iCal clients are a total mess, and nothing works consistently across Outlook, Gmail, and Apple Mail. The best approach is to go with the standard structure, but also add the same data as an attachment (like you're already doing). The only change you need to make in your code is to add this line:

$mail->Ical = $ical_content;

You also need to be very careful with your iCal content - Outlook is particularly picky, and the tiniest thing wrong will result in it not working at all, so I recommend testing using an iCal string generated by Outlook to start with, so that you isolate your iCal sending from any other issues you have relating to what's in it.

I have been using phpmailer for years for events and it has always worked. I always have problems only with apple. With IOS 13 I had to wait 4 months for them to fix it. Now with 14.4 the same problem, the yes/no/maybe buttons don't come out anymore so if I insert the event from iphone it doesn't synchronize it with outlook. Vice versa it works. If I accept it from iphone, I update the event and when I accept it from outlook automatically finds on the iphone what was an isolated event and updates it, I assume because the id is unique anyway. It's frunstrante apple side that continues to make mistakes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM