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

This is my code:

/* ------------------------------------------------------
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".

$message .= "This is a multipart message in MIME format.\n\n".
			"Content-Type: text/plain;charset=\"iso-8859-1\"\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));
		$data = chunk_split(base64_encode($data));

		echo "No attachment";

//Inserting a boundary to indicate the attachment start
$message .= "--{$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:


bdfbThis is a multipart message in MIME format.

Content-Type: text/plain;charset="iso-8859-1"


name="Dissertation Proposal.doc"

Member Avatar

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.