I would like to offer people to send an attachement together with the rest of their info in the form. Using this Stackoverflow answer and a lot of googling I'm almost happy with what I've got now. However there's a problem: When the user does not attach a file (which is ok) then I get errors that the Filename cannot be empty (the form gets submitted though).
EDIT: I don't want to enforce a file upload. On the contrary, I'm quite happy without a file. But (I think?) join(file($_FILES['f']['tmp_name']))
expects a file and if it doesn't get one will throw an error (while the form is still sent). So I'd like to change it in a way that this line is also ok without a file being uploaded. /EDIT
Unfortunately most of my knowledge comes via trial and error (and recognizing things I've done before). And no matter what I try or google I cannot find a way to avoid the error. Could anyone give me a hand?
if( empty($errors))
{
$s = md5(rand());
mail('email@example.com', 'attachment', "--$s
Hello World!
--$s
Content-Type: application/octet-stream; name=\"f\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
".chunk_split(base64_encode(join(file($_FILES['f']['tmp_name']))))."
--$s--", "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$s\"");
}
(The $errors makes sure the user provided an e-mail address in the form.)
Thanks a lot!