douqipi9704 2019-04-19 01:19
浏览 55

如何附加和发送刚用PHP上传的文件[重复]

This question already has an answer here:

I have an ajax form located in https://nkaccounting.desertsunstudio.com/careers

It successfully moves the uploaded file to a folder called temp_cv in the root.

My question is how do i get that file that to attach to an email and send it using PHP? i was hoping to not use a library like phpmailer...

    <form id="ajaxform_careers" action="/PHP/mailer.php" method="post" enctype="multipart/form-data">
    <input type="text" name="name" placeholder="Full Name" required></input>
    <input type="email" name="email" placeholder="Email" required></input>
    <input type="text" name="uploadmsg" placeholder="Please Upload your CV (.docx or .pdf only)" disabled></input>
    <div class="uploadbtn">
      <p>Upload.</p>
      <input type="file" name="cv_upload" accept="application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document"></input>
    </div>
    <textarea name="text" placeholder="Please write a brief description of yourself." required></textarea>
    <input type='text' name='hmnvr' placeholder="Human verification: Man's best friend is a ..." required></input>
    <button type="submit" name="submit" class="submit_btn" style="opacity: .7; cursor: default" disabled>Submit.</button>
    </form>

    <?php
    if(isset($_FILES['cv_upload'])) {

      $type = $_FILES["cv_upload"]['type'];
      //----------correct file type-------------
      if($type == "application/pdf" || $type == "application/msword" || $type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"){
        //----------upload success-------------
        $upload_dir = "../"."temp_cv/";
        $tmp_name = $_FILES["cv_upload"]["tmp_name"];
        $name = $_FILES["cv_upload"]["name"];
        if(@move_uploaded_file($tmp_name, "{$upload_dir}{$name}")){
          $headers = "From: NK Accounting <sal@desertsunstudio.com>
";
          $headers .= "MIME-Version: 1.0
";
          $headers .= "Content-Type: text/html; charset=ISO-8859-1
";
          $name = $_POST['name'];
          $email = $_POST ['email'];
          $text = $_POST['text'];
          $namer = $_FILES["cv_upload"]["name"];
          $attachpath ="../"."temp_cv/"."".$namer."";

          $msg ='Hello'
          // heres were i would execute the mail function

        } else {
          //----------upload failure-------------
          echo "<script>
            $('textarea').text('error sending attachment; please reload the page and retry.');
          </script>";
        }
      } else {
        //----------wrong file type-------------
        echo "<script>
          $('textarea').text('only word or pdf documents.');
        </script>";
      }
    }
    ?>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端