doutan5337 2014-02-18 08:43
浏览 54
已采纳

PHP邮件程序,未找到/检测到附件 - 所以,电子邮件未发送

I have add the code to my own form but I have this error:

"No attachment detected".

I am not a developer, so I'm a little confuse when I talk about code, sorry for that :(

This is my code:

 <label for="cv">Votre votre CV
     <span class="obligatoire">*</span>
 </label>
 <input type="file" class="validate[required,custom[cv]]" name="cv" class="cv" value="Votre CV au format PDF ou word uniquement" />   

and the code in reception:

$allowedExts = array("doc", "docx", "pdf");
$temp = explode(".", $_FILES["cv"]["name"]);
$extension = end($temp);
if ((($_FILES["cv"]["type"] == "application/pdf")
|| ($_FILES["cv"]["type"] == "application/msword"))

&& in_array($extension, $allowedExts))
  {
  if ($_FILES["cv"]["error"] > 0)
    {
    echo "<script>alert('Error: " . $_FILES["cv"]["error"] ."')</script>";
    }
  else
    {
        $d='telechargements/emploi/cv/';
        $de=$d . basename($_FILES['cv']['name']);
        move_uploaded_file($_FILES["cv"]["tmp_name"], $de);
        $fileName = $_FILES['cv']['name'];
        $filePath = $_FILES['cv']['tmp_name'];
        //add only if the file is an upload
     }
  }
else
  {
        echo "<script>alert('Invalid file')</script>";
  }

$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($_POST['email']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email']);
$mail->Subject = "Site Collin : Une réponse à l'offre de ".mb_strtolower($_POST['job'])."";
$mail->AddAttachment($_FILES['cv']['tmp_name'], $_FILES['cv']['name']);

For me, there is no error, so I don't understand why the file is not detected during the post.

Somebody can help me?

Thanks a lot!

  • 写回答

1条回答 默认 最新

  • duanbinian2243 2014-02-18 08:58
    关注

    Problem is in your HTML form . You are not letting user to select a file as you already filled value field with data witch is not a file value="Votre CV au format PDF ou word uniquement".

    it should look something like

    <input type="file" name="cv" />
    

    that way your POST will have a cv field with a value of file path.

    don't forget enctype="multipart/form-data" in your form.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀