我已经创建了一个php发送电子邮件脚本,通过php邮件发送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>
这是我的php文件
$path = "./uploads/";
$head = $_FILES["resume"]["name"];
$headtype = $_FILES["resume"]["type"];
$headtemp = $_FILES["resume"]["tmp_name"];
move_uploaded_file($headtemp, $path.$head);
$mail = new PHPMailer;
$client_email = $dt[3];
$mail->setFrom('noreply@xpertius.com', 'No reply');
$mail->addAddress("$client_email", 'Xpertius');
$mail->Subject = "Thank You For Appling - '".$job_title."'";
$mail->msgHTML($htmlbody);
$uploadfile1 = tempnam(sys_get_temp_dir(), sha1($_FILES['resume']['name']));
move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile1);
$mail->addAttachment($uploadfile1, $head);
我也尝试将其保存到y数据库,文件正确保存但不发送,因为附加文件链接在电子邮件中被破坏
解决方法:
您尝试移动上传的文件:
move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile1);
但是你已经把它移进了:
move_uploaded_file($headtemp, $path.$head);
最有可能的是,您尝试附加的文件为空(因为不再存在),检查电子邮件中的大小,或者在附加之前检查它是否仍然存在.
因此,您应该将$uploadfile1定义为:
$uploadfile1 = $path.$head;
代替你的第二个move_uploaded_file.