У меня проблема с отправкой почты PHP. Я пытаюсь отправить вложение с помощью PHP из онлайн-формы. Данные в письме, которое я получил, в порядке, но вложение иногда выглядит так:
2 application octet-stream; name=""
(это будет простой текст в виде приложения с этим именем). Что я делаю не так?
<?php
// if button is pressed - ACTION
if (isset($_POST['reg_application'])) {
// get fields into variables
$firstname = strip_tags($_POST['firstname']);;
$lastname = strip_tags($_POST['lastname']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
// get other form fields into variables
$country = strip_tags($_POST['country']);
$experience = strip_tags($_POST['experience']);
$englishlevel = strip_tags($_POST['englishlevel']);
$availability = strip_tags($_POST['availability']);
$licence = strip_tags($_POST['drivingLicence']);
$nursing = strip_tags($_POST['nursing']);
$signed = "Signed";
//Deal with the email
$to = 'example@example.com';
$subject = "+1 $country - $firstname $lastname";
//Deal with sending
//$message = strip_tags($_POST['message']);
$message = "ALL DETAILS\n\nFirst Name: $firstname\nLast Name: $lastname\nEmail: $email\nPhone: $phone\nCountry: $country\nExperience: $experience\nEnglish: $englishlevel\nAvailability: $availability\nDriving Licence: $licence\nNursing Experience: $nursing\nAccepted T&C: $signed";
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From: example@example.com\r\nReply-To: daniel@hidd.co.uk";
$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);
header("Location: success.php?application-sent");
}
?>