When I do an attachment, I could see additionally “ATT00407.txt” is getting attached along with this email which is empty. Please look into this issue. This is reflected only in the outlook

my code is :

$headers = "From: $from_name < $from_email >";   
	$email_txt ='';
	

	
	$semi_rand = md5(time()); 
	
	$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
		
	$headers .= "\nMIME-Version: 1.0\n" . 
				"Content-Type: multipart/mixed;\n" . 
				" boundary=\"{$mime_boundary}\""; 
	
	$email_message .= "This is a multi-part message in MIME format.\n\n" . 
					"--{$mime_boundary}\n" . 
					"Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
				   "Content-Transfer-Encoding: 7bit\n\n" . 
	$email_txt . "\n\n"; 

		$fileatt      = $_FILES['userfile']['tmp_name'];
		$fileatt_type = $_FILES['userfile']['type'];
		$fileatt_name = $_FILES['userfile']['name'];
		
		
		
		$data = file_get_contents($_FILES['userfile']['tmp_name']); 
		
		
		
		$data = chunk_split(base64_encode($data)); 
		
		$email_message .= "--{$mime_boundary}\n" . 
						  "Content-Type: {$fileatt_type};\n" . 
						  " name=\"{$fileatt_name}\"\n" . 
						  //"Content-Disposition: attachment;\n" . 
						  //" filename=\"{$fileatt_name}\"\n" . 
						  "Content-Transfer-Encoding: base64\n\n" . 
						 $data . "\n\n" . 
						  "--{$mime_boundary}\n"; 
		$attachment = $_FILES['userfile']['tmp_name'];

			$ok = mail($key, $email_subject, $email_message, $headers);

please help me fixing this problem

Regards

I suspect that the reason you are getting the ATT00407.txt is because the email client reads the attachment boundaries but finds nothing in between.

If there is a possibility of no file being uploaded then you should surround the attachment boundaries with an if statement to check that the file error is 0.

I have found that, on some servers, the file won't attach unless it is first moved from the temp directory(don't forget to delete it at the end).

You may find this page useful: http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

I kept getting in a tangle with this until I got my head around the content types and their associated boundaries.

Hope this helps ...
Simon.

I received the attached file in my mail, but I receive also the empty text file along with it. I don't know how come a txt file is attached with the attached file.

Thanks for the reply please help me fixing this problem

Take a look at the source of your email (make it one with a small attachment) and paste what you find here. Then we can get some idea of what your code is outputting .... my money is on a problem with the boundaries.

I have already given my code, i could not understand

Not the source of your code .... the source of your email (the actual email that you receive) ... so, when you read your email it is probably presented to you as either plain text or html depending on your settings. You will have an option to 'View source' somewhere ... that source will be useful for evaluating what's going wrong.

sorry i can't understand , please help me on it.

thanks for the reply

Whenever you receive an email, your email client (Outlook/Thunderbird/Windows Mail whatever) will display that email as either HTML or plain text depending upon your settings.

You do not see anything except that which you need to see. There is, in fact, a lot of information that you are not seeing.

If you select 'View Source' then you will see the actual text file that your PHP script created. This information will help us track down the problem.

You will probably find 'View Source' below the 'View' menu in Outlook. Which version of Outlook are you using?

Hope this makes some sense ...

Simon.

Be a part of the DaniWeb community

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