0

Hi,
I am using below code for sending attached mail
when i am sending an image as attachment i am getting image file in .txt extension.
Need suggestion for sending only image.

$file = $_FILES['uploadedfile']['name'];
				$target_path="upload/";
				$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
				move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
				$fileatt = $target_path; // Path to the file
				$email_from = "ab@gmail.com"; // Who the email is from
				$email_subject = "Post your add"; // The Subject of the email
				$email_message = "Name : ";
				$email_message .= $_POST['state']."<br>";
				$email_message .= "Message : ".$_POST['city']."<br>"; // Message that the email has in it
				$email_message .= "Email : ".$_POST['phone']."<br>";
				$email_to = "ac@gmail.com"; // Who the email is to hiddenemail
				
				$headers = "From: ".$email_from;
				$file = fopen($fileatt,'rb');
				$data = fread($file,filesize($fileatt));
				fclose($file);
				
				$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_message .= "\n\n";
				
				$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";
				
				$ok = @mail($email_to, $email_subject, $email_message, $headers);
				
				if($ok)
				{
					  echo '<script               language="javascript">alert("Thanks for applying!")</script>;';
				      echo "<script type='text/javascript'>";
				      echo  "window.close();n";
				      echo "</script>";
				} 
				else 
				{
				        echo '<script language="javascript">alert("Sorry!! but the email could not be sent. Please go back and try again!")</script>;';  
				        echo "<script type='text/javascript'>";
				         echo "window.location = 'index.php'";
				        echo "</script>";
				    	
				}
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pritaeas
0

Remove the = from line 30 and 40.

Now i am not getting attached image.
could you please give me code for sending image only

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.