내 문의 양식이 정상적으로 작동하지만 문의 양식을 사용하여 업로드 된 파일을 가져올 수 없습니다. 여기에 HTML 코드;PHPMailer 파일 업로드가 작동하지 않습니다.
<form id="contact_form" method="post" action="php/mail-advanced.php" enctype="multipart/form-data">
<input type="file" name="file" id="file" multiple />
<label for="file"></label>
<button type="submit" id="submit">SEND MESSAGE</button></form>
그리고이 코드는 php/mail-advanced.php 파일에 있습니다.
<?php
date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.example.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "pass";
$mail->setFrom('[email protected]', 'Example Message');
$mail->addReplyTo($email);
$mail->addAddress('[email protected]', 'Example Message');
$mail->Subject = $subject;
$mail->addAttachment($_FILES['file']);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
어떻게하면 PHPMailer에서 파일을 업로드 할 수 있습니까? 감사!
$ _FILES 배열을 다시 확인하십시오. – nogad
적절하고 안전하게 수행하십시오. [PHPMailer와 함께 제공되는 파일 업로드 예제] (https://github.com/PHPMailer/PHPMailer/blob/master/examples/send_file_upload.phps)를 따르십시오. – Synchro