There's nothing wrong with your code - it works fine for you on localhost (and also for me), so it must be an issue with your server environment. This could be several things:
Windows server with no mail server installed? It could be permissions for your uploaded files, or indeed the ability to upload files at all, since that is also controlled via php.ini.
I suggest you separate out the stages:
Upload a file and save it, check that it's there on the server.
Check that your PHP script can see and read the uploaded file (and
please read the
docs on how to do
this correctly).
Send a simple email without attachments. If that works you know your
mail server is ok.
When all the individual pieces are working, join them together.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…