【发布时间】:2017-12-19 21:43:14
【问题描述】:
我的联系表格运行良好,但我无法通过联系表格获取上传的文件。此处为 HTML 代码;
<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 = "noreply@example.com";
$mail->Password = "pass";
$mail->setFrom('noreply@example.com', 'Example Message');
$mail->addReplyTo($email);
$mail->addAddress('example@gmail.com', 'Example Message');
$mail->Subject = $subject;
$mail->addAttachment($_FILES['file']);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
如何在 PHPMailer 上通过文件上传获取文件?谢谢!
【问题讨论】:
-
再看$_FILES数组
标签: php forms file upload phpmailer