So frustrated!! Need help with mail() & sending attachm

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jjfletch
Forum Newbie
Posts: 13
Joined: Mon Apr 18, 2005 5:42 am

So frustrated!! Need help with mail() & sending attachm

Post by jjfletch »

I'm having a very frustrating time trying to figure out what keeps going wrong with this code. I just want the form to be able to mail an attachment, but no matter what, I keep getting the "Undefined index:filename" error.

I've tried setting the error reporting at different levels, but that doesn't seem to help. I'm convinced there's something wrong with the code.

Can someone help me out here? I'll post the relevant code below.

Code: Select all

if ($nm && $sp1 && $add && $e && $ph) {

	$sendTo = "abc@xyz.com";
	$subject = "Registration";

	$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 = "Logo file included: $name";

	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: " . $_POST["first_name"] ." " . $_POST["last_name"] ."<" . $_POST["email"] . ">\r\n";
	$headers .= "Cc: " . $_POST["email"] . "\r\n";
	$headers .= "Bcc: def@ghi.com" . "\r\n";
	$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
	$headers .= "Return-path: " . $_POST["email"]; 
	$headers .= "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\"";

	$message = "
	Company Name/Organization:	$nm
	Sponsorship Type:		$sp1
	Address:			$add
	Contact Person:			$con
	Email:				$e
	Phone:				$ph
	Fax:				$fx

	Sponsorship Type:
	";

	if (strlen($spt1) > 0) { $message .= "$spt1"; }
	if (strlen($sp_amt) > 0) { $message .= "$sp_amt"; }
	if (strlen($spt2) > 0) { $message .= "$spt2"; }
	if (strlen($spt3) > 0) { $message .= "$spt3"; }
	if (strlen($spt4) > 0) { $message .= "$spt4"; }
	if (strlen($spt5) > 0) { $message .= "$spt5"; }
	if (strlen($spt6) > 0) { $message .= "$spt6"; }
	if (strlen($spt7) > 0) { $message .= "$spt7"; }
	if (strlen($spt8) > 0) { $message .= "$spt8"; }
	if (strlen($spt9) > 0) { $message .= "$spt9"; }
	if (strlen($spt10) > 0) { $message .= "$spt10"; }
	if (strlen($spt11) > 0) { $message .= "$spt11"; }
	if (strlen($spt12) > 0) { $message .= "$spt12"; }
	if (strlen($spt13) > 0) { $message .= "$spt13"; }

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

	mail($sendTo, $subject, $message, $headers); 
	echo '<?php include ("spform.html"); ?> <p>Your sponsor form has been successfully submitted.  An email has been sent to you confirming the information.</p>';
}	
	} else {
	echo '<p><font color="red">Form could not be processed due to a system error</font></p>';
}


} else {

?>
Post Reply