I want to create a form which sends an email to an account. Creating this isnt the hard part, its trying to insert an attachment.
I created a form file with all needed attributes and so <input type="file" name="imgfile"> to upload an image.
My process form looks like this and works perfectly with only one problem. The image isnt attached, I only get to see its location an my PC.
Code:
<?php
// get posted data into local variables
$EmailFrom = Trim($_POST[EmailFrom]);
$EmailTo = "emailadres";
$Subject = Trim($_POST[Subject]);
$Naam = Trim($_POST[Naam]);
$imgfile = Trim($_POST[imgfile]);
// validation
$validationOK=true;
if (Trim($EmailFrom)=="" OR Trim($_POST[Subject])=="" OR $Naam = Trim($_POST[Naam])=="" OR $imgfile = Trim($_POST[imgfile])=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "$Naam ";
$Body .= "zou graag zijn evenement $Subject in de kijker plaatsen";
$Body .= "\n";
$Body .= "Hij geeft hiervoor $Prijs";
$Body .= "\n";
$Body .= "$imgfile";
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=succes.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
?>
Any idea´s?
I also tried with $_FILES but that just gave me the location on my server without the file
Code:
$uploaddir = '/path/to/your/image/files/'; // remember the trailing slash!
$uploadfile = $uploaddir. $_FILES['imgfile'];