我正在使用以下脚本来验证上传的文件是否为 pdf 以及是否使用 phpmailer 发送。它发送电子邮件,但没有附件。此外,它还允许我附加非 pdf 文件。请帮忙。
ob_start();
require("class.phpmailer.php");
if(isset($_FILES['upload']['tmp_name'])){
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime=finfo_file($finfo, $_FILES['upload']['tmp_name']);
if($mime=='application/pdf'){
$message = "some message";
$mail = new PHPMailer();
$mail->From = ('sample@youdomain.net');
$mail->AddAddress=('sample@youdomain.net');
$mail->Subject = "Submitted files";
$mail->Body = $message;
$mail->WordWrap = 50;
foreach($_FILES['upload']['tmp_name'] as $upload)
if(!empty($upload)) {
$mail->AddAttachment($upload);
}
$mail->Send();
header("Location: thankyou.php");
exit();
}}