我有一个问题,我想通过电子邮件使用 PHP 发送一个文件(Photoshop、.gif 等)文件。我将 HTML 文档中的数据发布到以下 PHP 文件。问题:我收到电子邮件,但文件已损坏。知道为什么这不起作用吗?
$to = 'admin@example.com';
$subject = 'Order';
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$plz = strip_tags($_POST['plz']);
$city = strip_tags($_POST['city']);
$street = strip_tags($_POST['street']);
$nr = strip_tags($_POST['nr']);
$plzdelivery = strip_tags($_POST['plz-delivery']);
$citydelivery = strip_tags($_POST['city-delivery']);
$streetdelivery = strip_tags($_POST['street-delivery']);
$nrdelivery = strip_tags($_POST['nr-delivery']);
$buttonsize = strip_tags($_POST['button-size']);
$count = strip_tags($_POST['count']);
$message = "Name: ".$name." Email: ".$email." Plz: ".$plz." Stadt: ".$city." Strasse: ".$street." Hnr: ".$nr." Button: ".$buttonsize." Anzahl: ".$count;
$type = $_FILES['file']['type'];
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
mail($to, $subject, $message, $headers);