PHP: creating iCal, how to create a new line in the description

I use the following to create a calendar prompt for Outlook for php script. However, \ n does not give me a new line in Outlook. Is there any way to do this? It seems silly if you cannot!

function addToCalendar($calEmail, $calSubject, $calDesc) { $calEmail = ' freelance@skinzy.org '; $description = $calDesc; $message="BEGIN:VCALENDAR VERSION:2.0 CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT DTSTART:20110718T121000Z DTEND:20110718T131000Z DTSTAMP:20110525T075116Z ORGANIZER;CN=TOMS TEST:mailto: system@skinzy.org UID:12345678 ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Yup:mailto: sample@test.com DESCRIPTION New \n Line LOCATION: I AM THE LOCATION SEQUENCE:0 STATUS:CONFIRMED SUMMARY: TEST SUMMARY TRANSP:OPAQUE END:VEVENT END:VCALENDAR"; $headers = "From: From Name <From Mail>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: text/calendar; method=REQUEST;\n"; $headers .= ' charset="UTF-8"'; $headers .= "\n"; $headers .= "Content-Transfer-Encoding: 7bit"; $subject = "Meeting Subject"; $subject = html_entity_decode($calSubject, ENT_QUOTES, 'UTF-8'); if(mail($calEmail, $calSubject, $message, $headers)) { echo "sent"; }else { echo "error"; } } 

This is the part of DESCRIPTION New \n Line that is having problems.

Any help would be greatly appreciated.

Tom

+4
source share
3 answers

You should replace \ r \ n \ n:

 $description = str_replace("\r\n", "\\n", $description); 

See also Encoding newlines in iCal files

+9
source

On Windows, you create a new line using \r\n .

More details:

\r in ASCII there is CR for "Carriage Return"
\n in ASCII there is LF for "Line Feed"

Windows requires a combination of both, while Linux systems just use \n .

On the page

+1
source

You can use =0D=0A for a new line with the appropriate encoding:

 DESCRIPTION;ENCODING=QUOTED-PRINTABLE:This is the first line.=0D=0AThe Second line.=0D=0AThe third line. 

or alternative approach (using base64):

 DESCRIPTION;FMTTYPE=text/html;ENCODING=BASE64:PHA+Tm9ybWFsIDAgZmFsc2UgZmFsc2UgZmFsc2UgTWljcm9zb2Z0SW50ZXJuZXRFeHBsb3JlcjQ8L3A+DQo8YnIgY2xhc3M9ImNsZWFyIiAvPg== 
0
source

Source: https://habr.com/ru/post/1390895/


All Articles