I'm trying to create an attachment that gets sent via email with PHP and PHPMailer. I'm not having trouble doing that, but I specifically need to create a file with a .ics
extension. I basically want the following to happen:
- Create a temporary file with a specific name, ie.
My Date.ics
- Write a string to that file.
- Attach the file and send the email.
- Close the file and delete it (via unlinking it).
Unfortunately, I can't get past step 1. Just doing:
$tmpfname = tempnam(sys_get_temp_dir(), 'My Date.ics');
echo $tmpfname;
Gives me my file name followed by six random characters. For example the above might say something like this:
/tmp/My Date.icsnn8B34
I've also gone into /tmp/
and the files aren't actually being deleted after they are unlinked via unlink($tmpfname);
How can I just get a temporary file with a specific extension?