如何将Word文档发送到电子邮件(PHP,Javascript)? [关闭]

I'm developing a site for a small business and I have a request where they want to allow people to submit their CV's. Therefore I need to allow a user to choose their CV and then click Send which sends the file to an email address.

I'm fairly new to web programming. Is this easy? I know PHP and a little javascript, would that be enough? I've looked around the web but have found many different answers and mostly about uploading to servers and not to emails.

Greatly appreciated!! I'm still learning :)

Massimino,

Irrespective of spamming and security issues & file types, here's a rough algorithm / workflow to follow which highlights the key features:

Step #1) Create your basic HTML Form pattern:
a) The form should be of type METHOD=POST method with an ACTION="[your-php-script]"
b) An input field of type="file" ( this allows you to select a file for uploading from your respective client os)

note: [your-php-script] refers to the actual php file which contains the application functionality for the server backend to accomplish your above task. (ie. "yourfile.php")

Step #2) In your php script you should perform the following:

a) Get the actual file name of the file just submitted by your user "Usually you will need to consult the global php array "$_FILES" for this info.

note: You can also obtain the file size and file extenstion in the event you would like to perform some additional filtering and /or validation.

b) (Optional) Perform any validation and/or filtering (ie. no windows exes ect.)

c) Save the file on your server. Copy from a temporary initial store to a server directory of your choosing.

d) Compose and send the Email with the File as an attachment. The easiest way to do this is using the php "PEAR" Library

Note: check with your hosting provider to see if they have uploaded this php module.

To fill in the actual details (ie implementation) from the above high level steps of the algorithm. I've found the following article helpful in html form guide.

regards, Scott

I would recommend forcing users to upload their CV as a PDF, this would make your life a lot easier from a security and integrity perspective. With this you and your clients would have the safeguarding that the document will not easily be modified.

Here is some example code using PHPMailer

<?php

require_once('../class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>

https://github.com/Synchro/PHPMailer