Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

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

      copy($file,$location);

      unlink($file);

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

   }

}

0
Justin Malone
Asked:
Justin Malone
2 Solutions
 
aksteveCommented:
I would use PHPmailer

http://phpmailer.sourceforge.net/

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "smtp1.site.com;smtp2.site.com"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "jswan";  // SMTP username
$mail->Password = "secret"; // SMTP password
$mail->From     = "from@email.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@site.com","Josh Adams");
$mail->AddAddress("ellen@site.com");               // optional name
$mail->AddReplyTo("info@site.com","Information");

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

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


if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
0
 
Marcus BointonCommented:
Before you can email the file, you need to handle the upload. There's lots of docs and examples here:

http://www.php.net/features.file-upload

Definitely use PHPMailer, just as aksteve says.
0
 
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now