Blueberry Hill
Blueberry Hill

Reputation: 119

PHP: How to send file as the attachment without uploading to sever?

How to send file by mail() function of PHP as the attachment without uploading file to sever (just after submiting the form, using $_FILES array)?

Upvotes: 0

Views: 3106

Answers (2)

Federico Finetti
Federico Finetti

Reputation: 7

get the file: $attachment = $_FILES['attachment']['tmp_name'];

get the file name: $attachment_name = $_FILES['attachment']['name'];

add the file to mail: $mail->addAttachment($attachment,$attachment_name);

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324780

If you're using the $_FILES array, the file is already uploaded to the server (usually in /tmp), so your question doesn't really make sense.

I understand what you mean, though. You want to send it as an attachment without moving it to a more permanent location. This can be done easily using
file_get_contents($_FILES['attachment']['tmp_name']);.

Upvotes: 5

Related Questions