Jump to content

email form with attachment


aladiyat23

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]

<?php

if(isset($_POST['submit'])){

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

$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" .
"--{$mime_boundary}--\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)"/>
</form>

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




Link to comment
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 :)
Link to comment
Share on other sites

  • 2 months later...
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.

Watts
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.