您好我收到了身体电子邮件,但我无法获得附件。我承认以前曾问过这个问题,但我对此有点新意,我面临着问题。我尝试了很多其他问题,但我没有得到这个。这是我的代码
<?php
//$to_mail = "architects@palavin.com,t.lavin@palavin.com,12yorkcourt@gmail.com";
$to_mail = "myemail@gmail.com";
//$cc="paul@enhance.ie";
$mail_sent = 0;
if(isset($_POST['submit'])){
//echo "the form was submitted";
$name = trim(strip_tags($_POST['name']));
if($name == "")
$error = true;
$email = trim(strip_tags($_POST['email']));
if($email == "")
$error = true;
$phone = trim(strip_tags($_POST['phone']));
$address = trim(strip_tags($_POST['address']));
$description = trim(strip_tags($_POST['description']));
$select = trim(strip_tags($_POST['select']));
$address = trim(strip_tags($_POST['address']));
$location = trim(strip_tags($_POST['location']));
$availability = trim(strip_tags($_POST['availability']));
$brand = trim(strip_tags($_POST['brand']));
$file_tmp_name = $_FILES['my_file']['tmp_name'];
$file_name = $_FILES['my_file']['name'];
$file_size = $_FILES['my_file']['size'];
$file_type = $_FILES['my_file']['type'];
$file_error = $_FILES['my_file']['error'];
if($file_error>0)
{
die('upload error');
}
//read from the uploaded file & base64_encode content for the mail
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode(($content)));
if($error != true){
$headers = 'From: "Contact Form" <no-reply@pintribe.com>'."\r\n";
//$headers .= 'CC: "'.$cc.'" <'.$cc.'>'."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "";
$subject = "PinTribe Form";
$boundary = md5(time());
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: application/octet-stream; name=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n\r\n";
$body .= $encoded_content ."\r\n";
$message = "New Contact message, received from: <br /> \n ";
$message .= "<b>Item Name</b> ".$name."<br /> \n";
$message .= "<b>Email</b> ".$email."<br /> \n";
$message .= "<b>Email</b> ".$brand."<br /> \n";
$message .= "<b>Contact Person</b> ".$phone."<br /> \n";
$message .= "<b>Address</b> ".$address."<br /> \n";
$message .= "<b>Category</b> ".$select."<br /> \n";
$message .= "<b>Description</b> ".$description."<br /> \n";
$message .= "<b>Location</b> ".$location."<br /> \n";
if(@mail($to_mail,$subject,$message,$headers))
{
echo "mail has been sent";
$mail_sent = 1;
}
else echo "mail not sent";
} else {
echo 'validation error';
}
}
?>
HTML
<form role="form" action="send_form_email.php" method="post" class="login-form" enctype="multipart/form-data">
<div class="form-group">
<span>Attach Photos</span>
<label class="btn btn-default btn-file fa fa-plus">
<input type="file" name="my_file">
</label>
<br>
<small>A maximum of 3 photos. Make sure Photos are bigger than 450 px X 850px</small>
</div>
<button type="submit" name="submit" class="btn">submit Form</button>
</form>
我可以看到一切都意味着收到了Body但无法接收附件