このコード(以下に添付)を使用すると、添付ファイル付きのメールを受信できませんが、URL成功のステータスが表示されます。私がunlink()を削除すると、自分のサーバのアップロードフォルダに添付ファイルがアップロードされます。 PHPMailerのコードに問題があると思います。誰でもそれを識別できますか?PHPMailer v6でメールを受け取ることができません
私はPHPMailer、uploads、index.php、upload.phpを私のディレクトリに持っています。
のindex.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
Name <input type="text" name="name"></input><br /><br />
Email <input type="email" name="email"></input><br /><br />
Upload <input type="file" name="file" required><br /><br />
<button type="submit" name="submit">SUBMIT</button>
</form>
</body>
</html>
upload.php
<?php
//Main Includes
use PHPMailer\PHPMailer\PHPMailer;
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
if (empty($name) || empty($email)) {
header("Location: index.php?empty");
exit();
} else {
//Check if input characters are valid
if (!preg_match("/^[a-zA-Z]*$/", $name)) {
header("Location: index.php?invalidname");
exit();
} else {
//Check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: index.php?emailerror");
exit();
} else {
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 10000000) {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$mail = new PHPMailer();
$mail->addAddress('[email protected]');
$mail->setFrom($email);
// $mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = $name;
$mail->addAttachment($fileDestination);
$mail->send();
unlink($fileDestination);
header("Location: index.php?uploadsuccess");
exit();
}
else {
echo "Your file is too big!";
}
} else {
echo "There was an error uploading your file!".$fileError;
}
} else {
echo "You cannot upload files of this type!";
}
}
}
}
}
最初の問題はここにあります// Mainは を使用します。PHPMailer \ PHPMailer \ PHPMailer; include_once "PHPMailer/PHPMailer.php"; include_once "PHPMailer/Exception.php"; –
すぐに電子メールを送信しないでください。$ mail = new PHPMailer(); print_r($ mail);あなたがメーラーを持っているかどうかを見てください。 –
@FaizKhanがあなたを取得できません... –