Jump to content

send form regardless if file selected or not


aladiyat23

Recommended Posts

Anyone know how to tweak the email attachment script so that a form is submitted regardless if a file is uploaded?

I think this is where i would make the change, just not sure how

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

Thanks!
ok here's a snippet of the form...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript" type="text/javascript">
function zxcEnableDisable(zxcobj){
zxcval=zxcobj.options[zxcobj.selectedIndex].value
if (zxcval.length<1){ return }
zxcenable=zxcval.split('^')[1].split(',');
for (zxc0=1;zxc0<zxcenable.length;zxc0++){
zxcobj=document.getElementById(zxcenable[zxc0]);
zxcobj.removeAttribute('disabled')
}
zxcdisable=zxcval.split('^')[0].split(',');
for (zxc1=1;zxc1<zxcdisable.length;zxc1++){
zxcobj=document.getElementById(zxcdisable[zxc1]);
zxcobj.setAttribute('disabled','disabled')
}


}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

  $to = "xxx";
  $subject = "Data Request";
  $email = $_POST['requiredemail'];
  $deaname = $_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'];
 
  $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
 
  $tmp_name = $_FILES['filename']['tmp_name'];
  $type = $_FILES['filename']['type'];
  $name = $_FILES['filename']['name'];
  $size = $_FILES['filename']['size'];
 
  $message = "
  From: $email\n
  Dealer Name: $deaname\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";
 
  if (file_exists($tmp_name)){
  if(is_uploaded_file($tmp_name)){
  $file = fopen($tmp_name,'rb');
  $data = fread($file,filesize($tmp_name));
  fclose($file);
 
  $data = chunk_split(base64_encode($data));
}

  $headers = "From: $email\r\n" .
  "MIME-Version: 1.0\r\n" .
  "Content-Type: multipart/mixed;\r\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";

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

if (@mail($to, $subject, $message, $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";
  }
} else {
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1">
<fieldset style="width: 375px; padding:10px"><legend>Which Task would you like to accomplish?</legend><br>
<select onChange="zxcEnableDisable(this);" name="selection">
  <option>Select One</option>
  <option value="D,tb1^E,tb2">Counts</option>
  <option value="D,tb2^E,tb1">Orders</option>
</select>
</fieldset>
<fieldset style="width: 375px; padding:10px" id="tb1">
<legend>Upload Your spreadsheet </legend>
<br>
<span>Selected Zip Codes (.xls)</span>
<input name="filename" type="file" size="30"/>
</fieldset>

<input name="submit" type="submit" value="Submit"/>

</form><?php } ?>

Archived

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

×
×
  • 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.