Problems, need help? Have a tip or advice? Post it here.
10 posts Page 1 of 1
Hi there couchies,

I'm working on a calendar function for a client. When a new calendar item is added I would like to automatically send an e-mail with ical file attached to the invitees.

I have created an ical script for the event successfully:

Code: Select all
<?php require_once('couch/cms.php'); ?>

<cms:content_type 'text/calendar' />
<cms:pages masterpage="ical-form.php">
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:<cms:show organizer_mail/>
DTSTAMP:<cms:show datestamp/>
ORGANIZER;CN=<cms:show organizer_name/>:MAILTO:<cms:show organizer_mail/>
DTSTART:<cms:show datestamp/>T<cms:show start_date/>00Z
DTEND:<cms:show datestamp/>T<cms:show end_date/>00Z
LOCATION:<cms:show location/>
SUMMARY:<cms:show summary/>
END:VEVENT
END:VCALENDAR
</cms:pages>

<?php COUCH::invoke(); ?>

And now i tried to add it to the e-mail with the help from this topic: viewtopic.php?f=8&t=6959
The file doesn't need to be uploaded though, it needs to be fetched from the server.
How could this be done?
Hi Saskia,

There is one more method of sending email now - using phpMailer library.
You can see it being used in the following thread -
viewtopic.php?p=16802#p16802

Related to it is this thread where the mail being sent has attachments -
viewtopic.php?p=17060#p17060

Although the attachment in the example above is an uploaded file, point is that phpMailer library also supports attaching physical files, which is what you want.

I suggest you please take a look at phpMailer's documentation on the Net and, I'm sure, you should be able to tweak the examples given above to send physical files as attachments.

Hope this helps.
Thanks KK, I'm almost there...
One thing though, for the calendar programme to understand the file is .ics and not .php I'm using a little PHP script. It doesn't work really well within a couch page though.

This is my script so far:
Code: Select all
<?php require_once('couch/cms.php'); ?>



<cms:pages masterpage="ical-form.php">
<cms:php>
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:<cms:show organizer_mail/>
DTSTAMP:<cms:show datestamp/>
ORGANIZER;CN=<cms:show organizer_name/>:MAILTO:<cms:show organizer_mail/>
DTSTART:<cms:show datestamp/>T<cms:show start_date/>00Z
DTEND:<cms:show datestamp/>T<cms:show end_date/>00Z
LOCATION:<cms:show location/>
SUMMARY:<cms:show summary/>
END:VEVENT
END:VCALENDAR";</cms:php>
</cms:pages>
<cms:php>
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo $ical;
exit;

</cms:php>
<?php COUCH::invoke(); ?>


I am assuming I have to use plain PHP for the whole page, I have absolutely no clue of how to do that though.
I think the following should do it -
Code: Select all
<?php require_once('couch/cms.php'); ?>
<cms:php>
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
</cms:php>

<cms:pages masterpage="ical-form.php">
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:<cms:show organizer_mail/>
DTSTAMP:<cms:show datestamp/>
ORGANIZER;CN=<cms:show organizer_name/>:MAILTO:<cms:show organizer_mail/>
DTSTART:<cms:show datestamp/>T<cms:show start_date/>00Z
DTEND:<cms:show datestamp/>T<cms:show end_date/>00Z
LOCATION:<cms:show location/>
SUMMARY:<cms:show summary/>
END:VEVENT
END:VCALENDAR
</cms:pages>

<?php COUCH::invoke(); ?>

Does it help?
Thanks KK, it almost works, it doesn't promt a download though :(
Please try the following -
Code: Select all
<cms:php>
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"calendar.ics\"\n");
</cms:php>
Yes, that worked.

Thanks KK, you're the best! :) :)
You are welcome :)
I have succeeded in getting an iCalendar attachment (.ics file) on an email message. Now, however, the body of the email is empty. Is there a way to populate the body of the email message AND attach an .ics file on the same email?
I just tried putting it outside of the <cms:if k_success> tag and it executed (Obviously with an error) - so what would be my next step?
From within the <cms:if> tag seems to do nothing, it won't even print an error.
10 posts Page 1 of 1