Attach file to email using php?

Take a look at docs.php.net/features.file-upload for the (file) upload part of the script swiftmailer.org/docs/message-attachments for sending emails with attachments.

I did something similar to this recently. It is not trivial. Your email message will have to be a multipart Mime message.

You will read in your file, encode it (using base64), then place it in your email message string in the correct spot. This looks like a decent tutorial (that I wish I had found before): texelate.co.uk/blog/send-email-attachmen... But note that the tutorial has some escape issues: $message . "“nn"; should be: $message ."\n\n"; You can also look into the Mail_Mime PEAR package for help: pear.php.net/package/Mail%5FMime.

This is what I have so far but its not working $_FILES = $_POST"resumeup"; if ((($_FILES"file""type" == "image/gif") || ($_FILES"file""type" == "image/jpeg") || ($_FILES"file""type" == "image/pjpeg")) && ($_FILES"file""size" 0) { echo "Error: " . $_FILES"file""error" . ""; } else { echo "Upload: " .

$_FILES"file""name" . ""; echo "Type: " . $_FILES"file""type" .""; echo "Size: " .

($_FILES"file""size" / 1024) . " Kb"; echo "Stored in: " . $_FILES"file""tmp_name"; } }.

Here is what I have done to send a mail with an attachment. Some of the code is mine and some of it has been taken from php.net/manual/en/function.mail.php. This code has been tried and tested so, it should work.

Also see if sendmail is installed. If on linux ubuntu system try sudo apt-get install sendmail to install it. The best part about this code is that it works for multiple file uploads.

File Name: index. Php $file) { // should output array with indices name, type, tmp_name, error, size $message . = "--{$mime_boundary}\n"; $fp = @fopen($file'tmp_name',"rb"); $data = @fread($fp,filesize($file'tmp_name')); @fclose($fp); $data = chunk_split(base64_encode($data)); $message .

= "Content-Type: application/octet-stream; name=\"". $file'name'. "\"\n"."Content-Description: ".

$file'name'. "\n" ."Content-Disposition: attachment;\n" . " filename=\"".

$file'name'."\";size=". $file'size'. ";\n"."Content-Transfer-Encoding: base64\n\n" .

$data . "\n\n"; } $message . = "--{$mime_boundary}--"; $returnpath = "-f" .

$from; $ok = @mail($to, $subject, $message, $headers, $returnpath); if($ok){ return 1; } else { return 0; } } //This function will correct file array from $_FILESfileposition to $_FILESpositionfile .. Very important function fixFilesArray(&$files) { $names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1); foreach ($files as $key => $part) { // only deal with valid keys and multiple files $key = (string) $key; if (isset($names$key) && is_array($part)) { foreach ($part as $position => $value) { $files$position$key = $value; } // remove old key reference unset($files$key); } } }? > By the way I would like to apologize for using sendmail since it is a bit slow. I will try to post a better solution.

Doesn't address the (more complicated) issue of attaching the uploaded file in an email. – Rob Oct 19 '09 at 20:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions