Jump to content


Photo

email form with attachment


  • Please log in to reply
4 replies to this topic

#1 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 21 July 2006 - 12:09 AM

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.


here's my php file

<?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";
}

?>

Here's partial html

<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






#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 21 July 2006 - 01:03 AM

User phpmailer...it makes sending email very easy.

http://phpmailer.sourceforge.net/

#3 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 21 July 2006 - 01:18 PM

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 :)

#4 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 21 July 2006 - 03:36 PM

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



#5 watts

watts
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 28 September 2006 - 08:22 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users