how do i get a form to upload a file to be attached to an e-mail

i have a pre-bult form that can be filled out and submited. when it get submited it sends a text e-mail with the information of all the fields in it. i want users to be able to upload a .doc file that gets attached to the e-mail that gets sent out. im pretty sure i have the code for it i just dont know how to set it up. this is part of whats in my formmail.php file

// check for a file if there is a file upload it

if ($file_name) {

   if ($file_size > 0) {

      if (!ereg("/$", $path_to_file))

         $path_to_file = $path_to_file."/";

      $location = $path_to_file.$file_name;

      if (file_exists($path_to_file.$file_name))

         $location .= ".new";



      $content .= "Uploaded File: ".$location."\n";



Justin MaloneSystem AdministratorAsked:
Who is Participating?
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.

I would use PHPmailer


$mail = new PHPMailer();

$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = ";"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "jswan";  // SMTP username
$mail->Password = "secret"; // SMTP password
$mail->From     = "";
$mail->FromName = "Mailer";
$mail->AddAddress("","Josh Adams");
$mail->AddAddress("");               // optional name

$mail->WordWrap = 50;                              // set word wrap
$mail->AddAttachment($file);      // attachment

$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the body";

   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;

echo "Message has been sent";

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
Marcus BointonCommented:
Before you can email the file, you need to handle the upload. There's lots of docs and examples here:

Definitely use PHPMailer, just as aksteve says.
Justin MaloneSystem AdministratorAuthor Commented:
Wow i completely forgot about this question, I have just been bussy. points to aksteve, and ill sort it all out later. thanks for the help
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.