Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未显示附件的PHPMailer附件路径文件名_Php_Html_Phpmailer - Fatal编程技术网

未显示附件的PHPMailer附件路径文件名

未显示附件的PHPMailer附件路径文件名,php,html,phpmailer,Php,Html,Phpmailer,PHPMailer附件问题: 当我执行var_dump$_文件时,它会显示数组中所有正确的内容,并将上载的文件移动到我的附件文件夹中,因此这一部分在我的表单中非常有效。我添加了表单属性enctype=multipart/formdata来通过服务器对表单数据进行编码 因此,我的问题是在表单提交后,尝试使用echo$file将$_files['attachment']路径文件名显示到页面。这不起作用,我不知道为什么 要提供我的文件结构的背景信息,请执行以下操作: 主目录文件夹:mailer for

PHPMailer附件问题:

当我执行var_dump$_文件时,它会显示数组中所有正确的内容,并将上载的文件移动到我的附件文件夹中,因此这一部分在我的表单中非常有效。我添加了表单属性enctype=multipart/formdata来通过服务器对表单数据进行编码

因此,我的问题是在表单提交后,尝试使用echo$file将$_files['attachment']路径文件名显示到页面。这不起作用,我不知道为什么

要提供我的文件结构的背景信息,请执行以下操作:

主目录文件夹:mailer for php 文件夹:附件 文件夹:图像 目录文件夹位于:供应商及其关联的编写器文件和PHPMailer sendmail-v2.php 以下是我的PHP代码:

<?php

if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $subject = $_POST['subject'];
  $email = $_POST['email'];
  $message = $_POST['message'];

//var_dump($_FILES);

if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] !="") {
  $file = "attachments/" . basename($_FILES['attachment']['name']);
  move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
} else{
  $file = " ";

echo $file;
}
} // end of post submit

?>
HTML表单代码:

<form method="post" action="sendmail-v2.php" enctype="multipart/form-data">
          <input type="text" class="form-control" name="name" placeholder="name">
          <input type="text" class="form-control" name="subject" placeholder="subject">
          <input type="email" class="form-control" name="email" placeholder="email">

          <textarea class="form-control" name="message" placeholder="enter message here" rows="3"></textarea>

          <input type="file" name="attachment" class="file-input form-control d-block mb-4" id="attachment-file">

          <!-- display pathfile selected to user -->
           <!-- <script type="text/javascript">
            document.getElementById('attachment-file').onchange = function () {
              alert('Selected file: ' + this.value);
            };
          </script> -->

          <input class="btn btn-primary" type="submit" name="submit" value="send email">
      </form>

你在else语句中加入了echo。把它放在外面,像这样

<?php

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];

//var_dump($_FILES);

if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] !="") {
$file = "attachments/" . basename($_FILES['attachment']['name']);
move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
} else{
$file = " ";
}
echo $file;

} // end of post submit

?>

希望这对您有所帮助

啊,祝您万事如意,谢谢您的收看。我显然是PHP新手,非常感谢。很高兴它帮助了我。接受它作为答案,以便帮助他人。我有另一个PHPMailer问题,如果你想帮助我,这里是链接[