Question: I'm trying to send an attachment with the phpMailer script.

Everything is working correctly since my email is sent correctly, however I do have a problem with an attachment that is not sent.

HTML part:

```
<p>
   <label>Attachment :</label>
   <input name="doc" type="file">
</p>

```

PHP:

```
<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();               
$mail->Host = '*****';  
$mail->SMTPAuth = true; 
$mail->Port = 465;
$mail->Username = '*****';  
$mail->Password = '*****'; 
$mail->SMTPSecure = 'ssl'; 

$mail->From = $_POST["name"];
$mail->FromName  = 'Your Name';
$mail->Subject   = 'Message Subject';
$mail->addAddress('*****');    

$mail->addAttachment($_FILES["doc"]); 
$mail->isHTML(true);   

$mail->Subject = 'Here is the subject';
$mail->Body    = "You got a new message from your website :

    Name:  $_POST[name]
    Company:  $_POST[company]
    Phone:  $_POST[phone]
    Email:  $_POST[email]
    Message:  $_POST[message]";

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

?>

<!DOCTYPE HTML>
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<p> <img src="img/correct.png" alt="icon" style=" margin-right: 10px;">Thank you! We will get back to you soon.</p>
</body>
</html>

```

Answer: 
```
Try:

    if (isset($_FILES['doc']) &&
        $_FILES['doc']['error'] == UPLOAD_ERR_OK) {
        $mail->AddAttachment($_FILES['doc']['tmp_name'],
                             $_FILES['doc']['name']);
    }

Basic example can also be found [here](https://code.google.com/a/apache-extras.org/p/phpmailer/wiki/AdvancedMail).

The function definition for `AddAttachment` is:

    public function AddAttachment($path,
                                  $name = '',
                                  $encoding = 'base64',
                                  $type = 'application/octet-stream')

```
Please have a look about how [PHP file uploads](http://es1.php.net/manual/en/features.file-upload.php) work. This array key:

```
$_FILES["doc"]

```

... will never contain a file. At most, it'll contain an array with information about where to find the file.