mail php attachment problem

I am trying to set up my script to send the content of a contact form via php mail.
When I add to attach the file attachment in the header of the email, then my message dissapears.
Any idea how I can work around this problem?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
If I understand your design concept, the client is expected to fill in a contact form and upload a file.  Is that right?
Nrupendra Nath PanigrahiCommented:
Code moved to Code snippet.
    	$output = '<h1>Thanks for your file and message!</h1>';
    	$flags = 'style="display:none;"';

    	//Deal with the email
    	$to = '';
    	$subject = 'attached file';

    	$message = strip_tags($_POST['message']);
    	$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
    	$filename = $_FILES['file']['name'];

    	$boundary =md5(date('r', time())); 

    	$headers = "From:\r\nReply-To:";
    	$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

    	$message="This is a multi-part message in MIME format.

Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

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


Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 


    	mail($to, $subject, $message, $headers);
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


<?php echo $output; ?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" <?php echo $flags;?>>
<p><label for="message">Message</label> <textarea name="message" id="message" cols="20" rows="8"></textarea></p>
<p><label for="file">File</label> <input type="file" name="file" id="file"></p>
<p><input type="submit" name="submit" id="submit" value="send"></p>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rivkamakAuthor Commented:
Your script worked, and I have now discovered that somehow it has to do with my message content that isn't coming through.
If the $message  = "test";
then it comes through in the email.
When I switch the message to look like this, then no data comes through.
$message .= "Following is an application submitted\n\n";
    $message .= "Charity Name: ".($_POST['charityName'])."\n";
    $message .= "charity Website: ".($_POST['charityWebsite'])."\n";
    $message .= "contact Phone: ".($_POST['contactPhone'])."\n";
    $message .= "Email: ".($_POST['Email'])."\n";
    $message .= "Address: ".($_POST['Address'])."\n";
	    $message .= "Mission: ".($_POST['Mission'])."\n";
    $message .= "Taxid Number: ".($_POST['TaxidNumber'])."\n";
		$message .= "\n\nSubmitted on ".date("F j, Y, g:i a");

Open in new window

HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Ray PaseurCommented:
Why not try printing the message to the browser window, so you can see what it contains?
rivkamakAuthor Commented:
the problem in my message above is the line that pulls the email. although I am not sure why.
If I take the post['email'] out , then I get the text.

#2, why do I get the attachement as a .dat file that doesn't open.
how can I just get the attachement as it is?
Ray PaseurCommented:
Something does not make sense here.  The original PHP script does not match the script fragment that contains information about charities.  Please, let's reorganize this question and its code snippets, so we can copy your code, install it on our own servers, and run it to see what it is doing.  We need you to create the SSCCE and post it here for us, thanks.
rivkamakAuthor Commented:
i changed the message to match the fields that I will need in the form.
So I realized that my file upload box has a different  name. I fixed that and now the upload works correctly. But again, the message isn't coming through.

	$message = "Following is an application submitted\n\n";
	  $message .= "message: ". strip_tags($_POST['message'])."\n";
  $message .= "Charity Name: ". strip_tags($_POST['charityName'])."\n";
  $message .= "Charity Name: ". strip_tags($_POST['charityName'])."\n";
    $message .= "charity Website: ". strip_tags($_POST['charityWebsite'])."\n";
   $message .= "contact Phone: ". strip_tags($_POST['contactPhone'])."\n";
//   $message .= "Email: ". strip_tags($_POST['Email'])."\n";
  $message .= "Address: ". strip_tags($_POST['Address'])."\n";
  $message .= "Mission: ". strip_tags($_POST['Mission'])."\n";
    $message .= "Taxid Number: ". strip_tags($_POST['TaxidNumber'])."\n";

Open in new window

Ray PaseurCommented:
Why not try printing the message to the browser window, so you can see what it contains?
If you do that, please post the message here so we can see what it contains, too.  You will need to use "view source" to copy the message -- the browser display will not be byte-by-byte accurate because of the way browsers render things like entities and whitespace.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.