Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get php mail() to send user uploaded image to my email address [duplicate]

Tags:

html

php

email

I'm creating my first website ever, which is for my custom tshirt business. I've created a form that allows a user to submit shirt constraints, which is emailed to me upon submission.

Everything is working except for the image, which only shows the file name in text. I'm guessing that I have to specify that its a file and not text?

I've looked around for an answer similar to this, but cannot find any posts with my specific problem.

Here's what I'm using and getting text only. All other variables are set up this way then called in a string variable, $message. Sorry for the noob question

<input type="file" multiple="multiple" name="fileUpload"><br>
$Image = $_POST["fileUpload"];
like image 873
Jake Stewart Avatar asked Dec 19 '25 05:12

Jake Stewart


1 Answers

Assuming you simply want to embed the picture, not send it as an attachment.

PHP uploaded files are not retrieved from $_POST array, but from $_FILE array.

Try this snippet:

$imageFile = $_FILES["fileToUpload"]["tmp_name"];
$imgEncoded = base64_encode(file_get_contents($imageFile));

and then, retrieve use it:

echo "<img alt='Embedded Image' src='data:image/png;base64,$imgEncoded' />";

or whatever your specific use case is.

like image 78
Wahib Mkadmi Avatar answered Dec 20 '25 18:12

Wahib Mkadmi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!