0

Hi all,

I re-post my previous thread I sent 2 days ago, because I am still having this problem with a php email application:
the code works fine, sends email messages and picks up the attachment
and its path as well, but instead of placing the attachment to the attachment part
of the mail it is displayed in the body as a gibberish, nonsense text.
I read lots of online threads about it, but have not found the solution for this
problem yet.
Could anyone help me, please? I am new to php, using Windows Vista at home
if that helps.

Many thanks
cycleFun

P.S.
This is my code:

<?php
/* ------------------------------------------------------
mm564_lib.php script
/* ------------------------------------------------------


/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$email = $_POST['recipient'];
$subject = $_POST['subject'];
$message = $_POST['messagebox'];

//Declaring MIME boundary
$mime_boundary = "==Multipart_Boundary_x".md5(time())."x";

// Building message headers
$headers = "Haho";

$headers .= "\nMIME-Version:1.0\n".
			"Content-Type:multipart/mixed;\n".
			"boundary=\"{$mime_boundary}\"";

$message .= "This is a multipart 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";


foreach($_FILES as $attachment)
{
	//File upload variables
	$tmp_name = $attachment['tmp_name'];
	$name = $attachment['name'];
	$type = $attachment['type'];
	$size = $attachment['size'];

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

	}else
	{
		echo "No attachment";
	}


//Inserting a boundary to indicate the attachment start
$message .= "--{$mime_boundary}\n".
			"Content-Type:{$type};\n".
			"name=\"{$name}\"\n".
			"Content-Disposition:attachment;\n".
			"filename=\"{$tmp_name}\"\n".
			"Content-Transfer-Encoding:base64\n\n".
			$data."\n\n".
			"--{$mime_boundary}--\n";

}

}

$message.= "--{$mime_boundary}--\n";

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email))
{
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "")
{
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email,$subject,$message,$headers))
{
echo "<h4>Thank you for sending email</h4>";
} else
{
echo "<h4>Can't send email to $email</h4>";
}
?>

And this is the result:

Haho
MIME-Version:1.0
Content-Type:multipart/mixed;
boundary="==Multipart_Boundary_xd41d2e728b037dd377a6273f72ef3ac6x"

bdfbThis is a multipart message in MIME format.

--==Multipart_Boundary_xd41d2e728b037dd377a6273f72ef3ac6x
Content-Type: text/plain;charset="iso-8859-1"
Content-Transfer-Encoding:7bit

bdfb

--==Multipart_Boundary_xd41d2e728b037dd377a6273f72ef3ac6x
Content-Type:application/msword;
name="Dissertation Proposal.doc"
Content-Disposition:attachment;
filename="/tmp/phppgVTGR"
Content-Transfer-Encoding:base64

0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAMwAAAAAAAAAA
EAAANQAAAAEAAAD+////AAAAADIAAAD/////////////////////////////////////////////
/////////////////////////////////////
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by diafol
0

Is this your script or somebody else's? If it's a script you picked up from somewhere, try the author or dedicated help forum.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.