Form to Email image attachments

This form is allowing me to upload small image files and send them as an attachment, but when someone tries to upload a file larger than 150k they get the following error:

The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.

To see the form online please go to http://www.aurtravel.com/html/gallery_form.php

Any help you can provide would be greatly appreciated. Thanks Traci

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AurTravel</title>
<link href="../Templates/text_styles.css" rel="stylesheet" type="text/css">

<!--Restricts Enter or Return function on form-->
<script type="text/javascript">
function noenter() {
  return !(window.event && window.event.keyCode == 13); }
</script>
</head>

<body>
<div style="border:5; border-color:#6699CC; border-style:double; width:755px;">
<table width="747" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td width="10"><img src="/images/spacer.gif" width="10" height="10"></td>
    <td width="737">
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

   // we'll begin by assigning the To address and message subject
   $to="[email protected]";
   $subject="Photo for AurTravel Gallery";

   $fromname = $_POST['fromname'];
   $fromemail = $_POST['fromemail'];
   $destination = $_POST['destination'];
   $location = $_POST['location'];
   $people = $_POST['people'];
    
   $destination2 = $_POST['destination2'];    
   $location2 = $_POST['location2'];
   $people2 = $_POST['people2'];
   
   $comments = $_POST['comments'];
   $success = '../html/gallery/success.html';      // Where to redirect after form is processed.
   $error = '../html/gallery/error.html';      // Where to redirect after error.

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // now we'll build the message headers
   $headers = "From: $fromrn" .
   "MIME-Version: 1.0rn" .
      "Content-Type: multipart/mixed;rn" .
      " boundary="{$mime_boundary}"";

   // here, we'll start the message body.
   // this is the text that will be displayed
   // in the e-mail
   $message="
   	Name: $fromname
	From email: $fromemail
	
	Photo 1
	
	Vacation destination: $destination
	Location: $location
	People in photo: $people
	
	Photo 2
	
	Vacation destination: $destination2
	Location: $location2
	People in photo: $people2
	
	Comments: $comments
	";      


   // next, we'll build the invisible portion of the message body
   // note that we insert two dashes in front of the MIME boundary 
   // when we use it
   $message = "This is a multi-part message in MIME format.nn" .
      "--{$mime_boundary}n" .
      "Content-Type: text/plain; charset="iso-8859-1"n" .
      "Content-Transfer-Encoding: 7bitnn" .
   $message . "nn";

   // now we'll process our uploaded files
   foreach($_FILES as $userfile){
      // store the file information to variables for easier access
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];

      // if the upload succeded, the file will exist
      if (file_exists($tmp_name)){

         // check to make sure that it is an uploaded file and not a system file
         if(is_uploaded_file($tmp_name)){
 	
            // open the file for a binary read
            $file = fopen($tmp_name,'rb');
 	
            // read the file content into a variable
            $data = fread($file,filesize($tmp_name));
			
            // close the file
            fclose($file);
 	
            // now we encode it and split it into acceptable length lines
            $data = chunk_split(base64_encode($data));
         }
 	
         // now we'll insert a boundary to indicate we're starting the attachment
         // we have to specify the content type, file name, and disposition as
         // an attachment, then add the file content.
         // NOTE: we don't set another boundary to indicate that the end of the 
         // file has been reached here. we only want one boundary between each file
         // we'll add the final one after the loop finishes.
         $message .= "--{$mime_boundary}n" .
            "Content-Type: {$type};n" .
            " name="{$name}"n" .
            "Content-Disposition: attachment;n" .
            " filename="{$fileatt_name}"n" .
            "Content-Transfer-Encoding: base64nn" .
         $data . "nn";
      }
   }
   // here's our closing mime boundary that indicates the last of the message
   $message.="--{$mime_boundary}--n";
   // now we just send the message
   if (@mail($to, $subject, $message, $headers))
	  echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$success.'">';
   else
	  echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$error.'">';
} else {
?>
<br /><p align="center" class="Blue24pts">Submit your vacation photo for the AurTravel Gallery</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" 
   enctype="multipart/form-data" name="gallery"  onsubmit="return formCheck(this);">
<div class="DarkGrey12pts">   
<script language="JavaScript">
<!--

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("fromname", "fromemail");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("First and last name", "Email Address");
	// dialog message
	var alertMsg = "Please complete the following fields:n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
// -->
</script>

<p class="Blue12pts">Contact Information:<p>First and last name: <input name="fromname" type="text" onKeyPress="return noenter()" style="color:#666666" size="30">
   <font color="#FF0000">*</font></p>
   
<!--Validate emil  -->   
   <script type="text/javascript">

/***********************************************
* Email Validation script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var emailfilter=/^w+[+.w-]*@([w-]+.)*w+[w-]*.([a-z]{2,4}|d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

</script>
<!--End Validate emil  -->    
   
   <p>E-mail address: <input name="fromemail" style="color:#666666" type="text" onKeyPress="return noenter()" size="30">
     <font color="#FF0000">*</font></p>
      
   <hr />
   
   <p align="center" class="Blue24pts">AurTravel vacation photo<br /><span class="Blue12pts"><em>Only two photo submissions per vacation, please.</em></span></p>
    <p class="Blue12pts">Photo 1: <input type="file" name="file1" style="color:#666666" onKeyPress="return noenter()"></p>
    
    
    <p>Vacation destination<br /><input name="destination" type="text" onKeyPress="return noenter()" value="example: Oahu, Hawaii;  Cancun, Mexico; Black Hills, South Dakota" style="color:#666666"  onfocus="this.select()"  size="100">
   </p>
    <p>Location of photo<br /><input name="location" type="text" onKeyPress="return noenter()" value="example: On the beach outside our hotel; Overlooking the ocean; Standing in front of Mount Rushmore" style="color:#666666" onfocus="this.select()" size="100">
   </p>
   <p>Name(s) of person in photo (if applicable)  <br /><input name="people" type="text" style="color:#666666" onKeyPress="return noenter()" size="100">
   </p>
   <p class="Blue12pts">Photo 2: <input type="file" name="file2" style="color:#666666" onKeyPress="return noenter()"></p>
   <p>Vacation destination<br /><input name="destination2" type="text" onKeyPress="return noenter()" value="example: Oahu, Hawaii;  Cancun, Mexico; Black Hills, South Dakota" style="color:#666666" onfocus="this.select()" size="100">
   </p>
    <p>Location of photo<br /><input name="location2" type="text" onKeyPress="return noenter()" value="example: On the beach outside our hotel; Overlooking the ocean; Standing in front of Mount Rushmore" style="color:#666666" onfocus="this.select()" size="100">
   </p>
   <p>Name(s) of person in photo (if applicable)  <br /><input name="people2" type="text" style="color:#666666" onKeyPress="return noenter()" size="100">
   </p>
   
   <p class="Blue12pts">Comments about your trip and/or working with AurTravel to plan your vacation: 
   <br /><TEXTAREA NAME="comments" COLS=75 ROWS=6 wrap="hard" style="color:#666666" onKeyPress="return noenter()"></TEXTAREA>
   </p>
   
   <p><input type="submit" onClick="return checkmail(this.form.fromemail)" name="Submit" value="Submit"></p>
   <div align="right"><font color="#FF0000">*</font> required field </div>
</form></div>
<?php } ?>

</td>
  </tr>
</table>
</div>


</body>
</html>

what’s your upload_max_filesize set at in the PHP.INI file?

I don’t know…How would I check or change it?

Traci

Open up your PHP.INI file in a text editor and search for upload_max_filesize.

On a *nix system, it’s generally located at /etc/php.ini

On a Windows system, I suspect it’s somewhere under the c:program files folder (I am not sure since mine is on a Linux box.)

It’s also possible to use ini_get() to retrieve php.ini information. Besides that, both Windows and Linux provide a desktop search mechanism ;)

Thanks. I will be increasing the file post and upload size.

One more question. For some reason the error page is not coming up. Any suggestions?

Thanks

Traci

What error page are you talkin about?

http://www.aurtravel.com/html/gallery_form.php

When you try to upload a photo that is over 2M the designated error page doesn’t execute, you just get an internet error:

The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.

Thanks

Traci

Perhaps the “Designated Error Page” is unavailable (can’t be found.) Do you have a custom error page, and if so is it configured correctly in apache (or whatever webserver you use)?

http://www.aurtravel.com/html/gallery/error.html

The error page is live and the link within the form is correct.

Sponsor our Newsletter | Privacy Policy | Terms of Service