douzen1880 2016-09-11 08:12
浏览 96

PhpMailer:无法访问文件错误,同时从tmp目录发送上传文件作为附件

I am trying to send the file which is uploaded and gets saved to tmp directory as an attachment. I am using PhPMailer but i am getting Could not access file error. The mail is getting sent with text in it on clicking submit but file which gets uploaded is not getting sent. I have gone through similar type of asked questions but none could solve the issue. Here is the code.

<?php 
if(isset($_POST['submit'])){
 include('PHPMailer_5.2.0/class.phpmailer.php');
        $content = 'Hello world!';

        $email = new PHPMailer();
        $email->From      = 'info@example.com';
        $email->FromName  = 'Your Name';
        $email->Subject   = 'Subject';
        $email->Body      = $content;
        $email->AddAddress( 'xxx@gmail.com' );
    $email->AddAttachment( $_FILES['fileUpload']['tmp_name'], $_FILES['fileUpload']['name'] );
        return $email->Send();
    }
?>
<html>
<head>
  <body>
    <form id="sunrise" name="sunrise" method="post" action="">
      <div class="form-group uploader col-xs-4">
        <label class="coole" id="no-print">Upload Child's Image:</label>
        <input name="fileUpload" type="file" id="fileUpload" class="no-print" required />
        <br />
        <div name="image-holder" id="image-holder"> </div>
      </div>
      <div class="col-xs-4">
        <input type="text" name="student_name" class="form-control" id="add_student_first_name" placeholder='Your Name' required>
      </div>
      <button type="submit" class="btn btn-default" id="no-print" name="submit" value="submit">Submit</button>
    </form>
    <script>
    $("#fileUpload").on('change', function() {

      if (typeof(FileReader) != "undefined") {

        var image_holder = $("#image-holder");
        image_holder.empty();

        var reader = new FileReader();
        reader.onload = function(e) {
          $("<img />", {
            "src": e.target.result,
            "class": "thumb-image",
            "width": "113px",
            "height": "151px"
          }).appendTo(image_holder);

        }

        image_holder.show();


        reader.readAsDataURL($(this)[0].files[0]);
      } else {
        alert("This browser does not support FileReader.");
      }
    });
    </script>
    <script type="text/javascript">
    document.getElementById('date').valueAsDate = new Date();
    </script>
  </body>
</html>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错
    • ¥15 单片机学习顺序问题!!
    • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
    • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)