您好,我正在尝试使用php邮件功能在电子邮件上发送表单数据。我在邮件中收到附件,但未收到表单数据。
下面是我的HTML表单代码:
<form class="contact-us" method="post" enctype="multipart/form-data">
<input id="name" name="fname" type="text" placeholder="Name" class="form-control input-md" value="">
<input id="phone" name="mobile" type="text" placeholder="Phone" class="form-control input-md" value="">
<input id="resume" name="attachment" type="file" placeholder="Upload Resume" class="form-control input-md" accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" >
<button type="submit" name="submit" value="submit" onClick="alert('jhg');" class="btn btn-default">Submit</button>
</form>
我的PHP代码是
<?php
if(isset($_POST['submit']))
{
$file=$_FILES['attachment']['name'];
move_uploaded_file($_FILES['attachment']['tmp_name'],$file);
//recipient
$to = 'seo@gmail.com';
//sender
$from = 'admin@mail.co.uk';
$fromName = 'My Name';
//email subject
$subject = 'Enquiry ';
$ThanksURL = "http://www.mysite.co.uk"; //confirmation page
//attachment file path
//email body content
$htmlContent = '<h1>Heading</h1>
<p>Enquiry</p>';
//header for sender info
$headers = "From: $fromName"." <".$from.">";
//boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
//multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
//preparing attachment
if(!empty($file) > 0){
if(is_file($file)){
$message .= "--{$mime_boundary}\n";
$fp = @fopen($file,"rb");
$data = @fread($fp,filesize($file));
@fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" .
"Content-Description: ".basename($file)."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $from;
//send email
$mail = @mail($to, $subject, $message, $headers, $returnpath);
//email sending status
echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1>";
unlink($file);
}
?>
在上面,我只在邮件中收到附件,而没有表格数据。
请帮助解决此问题。