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 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog