Question: I have a website that builds simple Word files from details that users insert.
I need to create Word files and send them to email.
I know how to send files with email.
I know how to create Word files with php:

```
    <?php
  header("Content-type: application/vnd.ms-word");
  header("Content-Disposition: attachment;Filename=document_name.doc");    
  echo "<html>";
  echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
  echo "<body>";
  echo "<b>My first document</b>";
  echo "</body>";
  echo "</html>";
?>

```

For example I accept name of same user, create the Word file just with this name, and send the file to emai.

But after I use this code it just uploads the file. How can I send this to email?

Answer: 
Do you mean you don't know how to put the generated Word document into a physically file ? That you can then use with your email code that you already have ?

If the above code is an example of how you generate your Word document then you could do something like this.

```
<?PHP

// Get the generated MS Word document data
$ms_word_data = file_get_contents("http://url.to.ms.word.create.file.php");

// Create a temporary file to use as email attachment
$word_temp_file = tmpfile();

// Write your generated MS Word data into the temporary file
fwrite($word_temp_file, $ms_word_data);

// Use the file in your E-Mail code
...
$attachment_file = $word_temp_file;
...

// When you have sent your E-Mail don't forget to do house keeping.
// This will close your filepointer but also delete the temporary
// file your have created.
fclose($word_temp_file);

?>

```
This can be achieved through PHPMailer, set it up then add this to attach particular word file to your e-mail
You can get PHPMailer from [here][1]

```
$email = new PHPMailer();
$email->From      = 'youremail@xyz.com';
$email->FromName  = 'Name';
$email->Subject   = 'Sub';
$email->Body      = $body;
$email->AddAddress( 'recievers@email.com' );

$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';

$email->AddAttachment( $file_to_attach , 'wordfile.txt' );

```

and finally

```
return $email->Send();

```

This way you can attach a file to the email.