Jump to content


This topic is now archived and is closed to further replies.


email form with attachment

Recommended Posts

I really need help with this php script. I get no errors after submitting and the user is taken to the confirmation page. I'm sent an email with the input field info but no attachment. I'd appreciate any help while I learn this stuff.

[color=red]here's my php file[/color]



$to = "xxx";
$subject = "Data Request";
$email = $_POST['requiredemail'];
$name = $_POST['requireddealername'];
$address = $_POST['requiredaddress'];
$zip = $_POST['requiredzip'];
$quanity = $_POST['requiredquanity'];
$list = $_POST['requiredlist'];
$range = $_POST['range'];
$year = $_POST['year'];
$make = $_POST['make'];
$other = $_POST['other'];
$headers = "From: $email \r\n";

$fileatt = $_FILES['uploadedfile']['tmp_name'];
$fileatt_type = $_FILES['uploadedfile']['type'];
$fileatt_name = $_FILES['uploadedfile']['name'];

            if (is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));

$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}\"";

$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" .
$message . "\n\n";

$data = chunk_split(base64_encode($data));

$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .

//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .

$body = "
From: $email\n
Dealer Name: $name\n
Address: $address\n
Zip: $zip\n
Quanity: $quanity\n
List: $list\n
Range: $range\n
Year: $year\n
Make: $make\n
Other: $other\n";

mail($to, $subject, $body, $headers);
echo '<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=http://www.dmmipromotions.com/submission.html">';
} else {
echo "An error has occured. Please fill out the form and try again";


[color=red]Here's partial html[/color]

<form onsubmit="return checkrequired(this)"  ENCTYPE="multipart/form-data" method="post" action="xxx">

<input class="formfield-data" name="uploadedfile" type="file" size="30" />

<input name="submit" type="submit" class="formfield-data" value="Upload & Submit" onclick="LimitAttach(this.form, this.form.attachment.value)"/>

I'd really really appreciate any tips or help with this. If I left anything out to help you help me just let me know ;)

Thank you

Share this post

Link to post
Share on other sites
Thanks for the reply hitman, but i'd like to learn why the code i posted isnt attaching the uploaded document into the emails. I'm really hoping to grasp php so maybe when I'm comfortable working with it I'll take an easier route like phpmailer.

Thanks :)

Share this post

Link to post
Share on other sites
okay, so is this just too hard to get help on? is it that far off that its beyond script advice?

Share this post

Link to post
Share on other sites
I can't answer why your code isn't working but using phpmailer doesn't stop you from learning php.  It's just a class that has been created to make it easier to send email and allows you to do things that can be quite complicated using just the php mail() class.  I would check out the site and see what you think before you dismiss it.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.