Php pdf未作为附件发送

Php pdf未作为附件发送,php,pdf,phpmailer,Php,Pdf,Phpmailer,我已经创建了一个php发送电子邮件脚本,通过php mailer发送pdf以及附件。当我发送电子邮件时,附件无法作为附件发送。附件已损坏。没关系。请查看我的代码,让我知道我犯了什么错,为什么附件发送不正确 这是我的html <form method="POST" action="details.php?id=<?php echo $_GET['id']; ?>" enctype="multipart/form-data"> <div class="col c

我已经创建了一个php发送电子邮件脚本,通过php mailer发送pdf以及附件。当我发送电子邮件时,附件无法作为附件发送。附件已损坏。没关系。请查看我的代码,让我知道我犯了什么错,为什么附件发送不正确

这是我的html

<form method="POST" action="details.php?id=<?php echo $_GET['id']; ?>" enctype="multipart/form-data">
    <div class="col col_center">
        <input name="first_name" class="firstname text_input" type="text" placeholder="First Name">
    </div>
    <div class="col col_center">
        <input name="last_name" class="lastname text_input" type="text" placeholder="Last Name">
    </div>
    <div class="col col_center">
        <input name="email" class="email_address text_input" type="email" placeholder="Email Address">
    </div>
    <div class="col col_center">
        <input name="phone" class="phone text_input" type="tel" placeholder="Phone (with country code)">
    </div>
    <input type="hidden" name="title" value="<?php echo $dt['job_title']; ?>" />
    <div class="btn_row">
        <input type="file" value="Attach CV" class="button blue" name="resume" style="width:auto;">
    </div>
    <div class="btn_row">
        <input type="submit" value="Send" name="submit_resume" class="button" style="width:auto;">
    </div>
</form>

我还尝试将其保存到y数据库,文件已正确保存,但未发送,因为电子邮件中的附件链接已断开

您尝试移动上载的文件:

move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile1);
但您已经将其移入:

move_uploaded_file($headtemp, $path.$head);
最可能的情况是,您尝试附加的文件是空的(因为它已不存在),请检查电子邮件中的大小,或者在附加之前检查它是否仍然存在

因此,您应该将$uploadfile1定义为:

$uploadfile1 = $path.$head;
代替你上传的第二个移动文件。

试试这个

 $mail->AddAttachment($_FILES["resume"]['tmp_name'],
                     $_FILES["resume"]['name']);

同时检查要将文件移动到的文件夹权限,该文件夹应为可写的

检查错误。您还应该发布此的html表单。好的,我正在发布html,没有错误,正在成功发送emall,但附件已损坏。我有更新我的问题,请看一看我不知道
tempnam()
做了什么。作为附件发送的语法是
addAttachment($tempFile,$fileName)
。即:
$mail->AddAttachment($\u FILES['file']['tmp\u name'],$\u FILES['file']['name'])
我建议您将代码基于PHPMailer提供的脚本。该文件已被移动,因此无法在
$\u文件['resume']['tmp\u name']
中访问该文件。然后在移动之前执行该操作不,不要,这是一个安全风险,正如PHP文档所说;您必须先使用
move\u uploaded\u file
。好的,所以我必须在发送电子邮件后将文件移动到文件夹??我使用了您的方法,现在接收的电子邮件没有附件电子邮件中的附件大小为0kb
 $mail->AddAttachment($_FILES["resume"]['tmp_name'],
                     $_FILES["resume"]['name']);