Right... well due to some help before, but mainly my fanatical net browsing, I managed to get it all to work in the end... I can send an attachment from my form via mime through email.
My little problem is now, that in my form I have two File fields... So I would like to send two files... not cracked it yet... I'd also like to restrict the files to gif, jpeg and bmp file extensions.
Here is my code so far that works...
<?php
$fileatt = "$File_a";
$email_from = "$email";
$email_subject = "New Registration";
$email_to = "simon@peekabou.com";
$errorurl = "http://www.peekabou.com/error.htm" ;
$thankyouurl = "http://www.peekabou.com/thanks.htm" ;
$http_referrer = getenv( "HTTP_REFERER" );
$name = $POST['name'] ;
$aka = $POST['aka'] ;
$address = $POST['address'] ;
$city = $POST['city'] ;
$country = $POST['country'] ;
$postcode = $POST['postcode'] ;
$email = $POST['email'] ;
$File_a = $FILES['File_a'] ;
$file_name = $FILES['File_a']['name'];
$file_size = $FILES['File_a']['size'];
$file_type = $_FILES['File_a']['type'];
if ($file_size > 5000000) {
header( "Location: $errorurl" );
exit ;
}
if (empty($name) || empty($email) || empty($address) || empty($city) || empty($country) || empty($postcode)) {
header( "Location: $errorurl" );
exit ;
}
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message =
"-------------- Registration information --------------\n\n" .
" Name: $name\n".
" AKA: $aka\n".
" Address: $address\n".
" City: $city\n".
" Country: $country\n".
" Postcode: $postcode\n".
" Email: $email\n".
"\n----------------------------------------------------------------\n" ;
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_type};\n" .
"name=\"{$flie_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$file_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
header ( "Location: $thankyouurl" );
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>
So... can anyone out there help me?😉
Love you all,
Simon.