0

Community, I am testing out a very basic form where I can select a single file and send the file to myself. I have looked at a few other members postings and have followed very similar steps. below is my html and php. It will send the email, but won't attach the file. Any suggestions as to what I'm doing wrong or if I'm missing anything?

<form method="post" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER['PHP']);?>">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if($_POST['submit'] == 'Submit')
{
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    $mail->From = "*****@*****.com";
    $mail->AddAddress("*****@******.com");
    $mail->Subject = "Test";
    $mail->Body = "HI";
    $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
    if(!$mail->Send())
    {
        echo 'Message was not sent.';
        echo 'Mailer error:'.$mail->ErrorInfo;
    }
    else
    {
        echo 'Message has been sent';
    }
}
?>
CBC_NS
  • 1,961
  • 4
  • 27
  • 47

0 Answers0