$attachment = chunk_split(base64_encode(file_get_contents($doc)));
$attachment = chunk_split(base64_encode($doc));
$doc = $pdf->Output('test.pdf', 'S');
Getting MIME encoding to work by hand is very difficult, especially when you are adding complicated attachments, I would definitely recommend using a mailing library as mention on your question. Incidentally, you seem to be telling it the filename is attachment.zip and it is a zip file, at no point have you zipped the PDF.
I don't get any more errors, but the file is never attached. The email I'm sent has an attachment "noname" at 0kb. Any thoughts on why this might be? Thanks for your help.
I think you have a superfluous command there. You are using the string variant of the Output() command:
It is not a file, it is a file in a string, as file_get_contents() would return if $doc was a filename.
Then you are performing a file_get_contents() on it: