Sorry voor de on overoverzichtelijke code, ik weet dat het niet netjes is en bestaat uit van alles en nog wat. Maar hij doet het tenminste (gedeeltelijk) :)
Wat ik in mijn mail krijg:
This is a multi-part message in MIME format. --6657a30d9b77d2e80a65b8aaafafc80f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit --6657a30d9b77d2e80a65b8aaafafc80f Content-Type: application/xml; name="Rabobank.png" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Rabobank.png"
Gebruikersnaam: rubjo99
Volledige naam: ruben kok
Klantnummer: 1234567890
Productnaam: Hurdur 827UI
Artikelnummer 1234567890
Badgenummer 10.09.29.09
Aantal 2
Aankoopdatum rubjo99
Klantenreferentie rubjo99
Klachtomschrijving:
HURDHURUDHUHSUDHSUDHUSADH
--6657a30d9b77d2e80a65b8aaafafc80f--
De code:
<?PHP
$klnummer = $_POST[klantNummer];
$arnummer = $_POST[artikelNummer];
// Configuration - Your Options
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = './uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
$filename = $_FILES['fileAttach']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['fileAttach']['tmp_name'],$upload_path . $filename)) {
echo "Bestand is geupload";
}
if (!isset($_REQUEST["userName"], $_REQUEST["fullName"], $_REQUEST["klantNummer"], $_REQUEST["productNaam"], $_REQUEST["artikelNummer"], $_REQUEST["badgeNummer"], $_REQUEST["klachtDesc"], $_REQUEST["klantRef"]))
{
echo "Je hebt 1 van de velden niet ingevuld";
}
elseif (!eregi( "^[0-9]+$", $klnummer )) {
echo "Het artikelnummer en/of klantenummer kan alleen cijfers bevatten!";
}
elseif (!eregi( "^[0-9]+$", $arnummer )) {
echo "Het artikelnummer en/of klantenummer kan alleen cijfers bevatten!";
}
else
{
$mailInfo=array();
foreach($_POST as $k=>$v){
if($k!='day' && $k!='month' && $k!='year'){
$mailInfo[$k]=htmlspecialchars($_POST[$k]);
}
}
$aankoopdatum = "".$_REQUEST["day"]."-".$_REQUEST["month"]."-".$_REQUEST["year"]."";
$to = "[email protected]";
$from = "From:". $mailInfo['fullName'] ."";
$eigen_emailadres = '[email protected]';
$error_emailadres = '[email protected]';
$naam_verzender = 'Afzender';
$email_verzender = '[email protected]';
$bcc_emailadres = '';
$html = true;
/* Attachment File */
// Attachment location
$file_name = $_FILES['fileAttach']['name'];
$path = "./uploads/";
// Generate a boundary
$boundary = md5(uniqid(time()));
// Read the file content
$file = $path.$file_name;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($message));
// Email content
$message = "<html><body>";
$message .= "<table>";
$message .= "<tr><td>Gebruikersnaam:</td><td>".$mailInfo['userName']."</td></tr>";
$message .= "<tr><td>Volledige naam:</td><td>".$mailInfo['fullName']."</td></tr>";
$message .= "<tr><td>Klantnummer:</td><td>".$mailInfo['klantNummer']."</td></tr>";
$message .= "<tr><td>Productnaam:</td><td>".$mailInfo['productNaam']."</td></tr>";
$message .= "
<tr>
<td>Artikelnummer</td>
<td>".$mailInfo['artikelNummer']."</td>
</tr>
<tr>
<td>Badgenummer</td>
<td>".$mailInfo['badgeNummer']."</td>
</tr>
<tr>
<td>Aantal</td>
<td>".$mailInfo['aanTal']."</td>
</tr>
<tr>
<td>Aankoopdatum</td>
<td>".$mailInfo['userName']."</td>
</tr>
<tr>
<td>Klantenreferentie</td>
<td>".$mailInfo['userName']."</td>
</tr>";
$message .= "<tr><td>Klachtomschrijving:</td><td><pre style='font-size:12px;'>".$mailInfo['klachtDesc']."</pre></td></tr>";
$message .="</table>";
$message .="</body></html>";
//Headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $fullname . ' <' . $email_verzender . '>' . PHP_EOL;
$headers .= 'Reply-To: ' . $naam_verzender . ' <' . $eigen_emailadres . '>' . PHP_EOL;
// Multipart wraps the Email Content and Attachment
$headers .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n". PHP_EOL;
$headers .= "This is a multi-part message in MIME format.\r\n". PHP_EOL;
$headers .= "--".$boundary."\r\n". PHP_EOL;
// Content-type can be text/plain or text/html
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n". PHP_EOL;
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n". PHP_EOL;
$headers .= "$content\r\n". PHP_EOL;
$headers .= "--".$boundary."\r\n". PHP_EOL;
// Attachment
// Edit content type for different file extensions
$headers .= "Content-Type: application/xml; name=\"".$file_name."\"\r\n". PHP_EOL;
$headers .= "Content-Transfer-Encoding: base64\r\n". PHP_EOL;
$headers .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n". PHP_EOL;
$headers .= $message."\r\n". PHP_EOL;
$headers .= "--".$boundary."--". PHP_EOL;
mail($to,"Klachtenformulier",$message,$headers);
echo 'Uw klacht zal zo snel mogelijk worden behandeld';
}
?>