Jump to content

[SOLVED] email attachment


dumdumsareyum

Recommended Posts

I am trying to send an email with an attachment. The attachment file type should be pdf or doc. I check the file submitted in my form for this extension and then email it. It is working good except the file shows up with no extension. I tried appending the file extension I had found earlier to check the file type, but it didn't work. I think my problem may lie in that my attachment type is listed as "application", but I don't know what the appropriate attachment type would be as the part to send the attachment was a copy past job  :)  Help please?

 

if($_POST)
           {
		 //check if a file was uploaded move to uploads
		   if(sizeof($_FILES > 0))
		      {
		        $file_ext = strrchr($_FILES['resume']['name'], '.');

		        $file_ext = strtolower($file_ext);
		        if($file_ext == ".pdf" || $file_ext == ".doc" || $file_ext == ".docx")
		        {

		 		           $tempfile = $_FILES['resume']['tmp_name'];
		                   $origin = $_FILES['resume']['name'];
		                   $date = date(mdY);
		                   $time = date(His);




		 		                  //send email
						   	      ini_set(sendmail_from, "[email protected]");


						   	      // Additional headers
						   	      $headers .= 'To: <exampleemail@example>' . "\r\n";


						   	      $fileatt = "$tempfile"; // Path to the file
								  $fileatt_type = "application/octet-stream"; // File Type
								  $fileatt_name = "resumeD$dateT$time$file_ext"; // Filename that will be used for the file as the attachment

								  $email_from = "[email protected]"; // Who the email is from
								  $email_subject = "Resume Received"; // The Subject of the email
								  $email_txt = "A resume as been received from the Houston Controls website"; // Message that the email has in it

								  $email_to = "[email protected]"; // Who the email is too

								  $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";



						   	      if( @mail($email_to, $email_subject, $email_message, $headers))
						   	        {
						   	        echo "<p class='message'>Your resume has been received.  You may also <a href='a href=$path/jobs/application.php'>submit an application</a> at this time if you have not already done so.</p>";
						   	        }
						   	        else
						   	        {
						   	         echo "<p class='message'>We were unable to receive your resume at this time. Please try again later or call our office at 713.672.1200.</p>";
						   	        }



		 		}  //end of file file_ext
		 		else
		 		{ $message="type";}

		 	  } //end of if sizeof(files)

Link to comment
https://forums.phpfreaks.com/topic/148260-solved-email-attachment/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.