社区,我正在测试一个非常基本的表单,我可以选择一个文件并将文件发送给自己。我看了几个其他成员的帖子,并遵循了非常类似的步骤。下面是我的HTML和PHP。它会发送电子邮件,但不会附加文件。关于我做错了什么或者我错过了什么的任何建议?
<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';
}
}
?>