Answer the question
In order to leave comments, you need to log in
How to fix an error in the feedback form with a file attachment?
Hello, there is a feedback form on the site, everything works well, except for attaching a file i.e. instead of a file, some kind of encoding, apparently of the entire file, comes to the mail.
<?php
if (isset($_POST['name'])) {$name = $_POST['name']; if ($name == '') {unset($name);}}
if (isset($_POST['email'])) {$email = $_POST['email']; if ($email == '') {unset($email);}}
if (isset($_POST['sub'])) {$sub = $_POST['sub']; if ($sub == '') {unset($sub);}}
if (isset($_POST['body'])) {$body = $_POST['body']; if ($body == '') {unset($body);}}
if (isset($name) && isset($email) && isset($sub) && isset($body)){
$boundary = md5(date('r', time()));
$filesize = '';
$address = "[email protected]";
$sub1 ="Отправка письма с формы обратной связи';
$mes = "Имя: $name \nE-mail: $email \nТелефон: $sub \nКомментарий: $body";
$mes="
Content-Type: multipart/mixed; boundary=\"$boundary\"
--$boundary
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit
$mes";
for($i=0;$i<count($_FILES['fileFF']['name']);$i++) {
if(is_uploaded_file($_FILES['fileFF']['tmp_name'][$i])) {
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['fileFF']['tmp_name'][$i])));
$filename = $_FILES['fileFF']['name'][$i];
$filetype = $_FILES['fileFF']['type'][$i];
$filesize .= $_FILES['fileFF']['size'][$i];
$mes.="
--$boundary
Content-Type: \"$filetype\"; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$filename\"
$attachment";
}
}
$mes.="
--$boundary--";
$send = mail ($address,$sub1,$mes,"Content-type:text/plain; charset = UTF-8\r\nFrom:$email");
if ($send == 'true')
{echo "Через несколько секунд вас перенаправит на главную страницу сайта <a href='http://arttou.me/'>arttou.me</a>";}
else {echo "!";}
}
else
{
echo "Вы что-то ввели не верно либо заполнили не все поля пожалуйста вернитесь и повторите попытку";
}
?>
Answer the question
In order to leave comments, you need to log in
You incorrectly form the body of a multipart letter. Either read the RFC, or take a ready-made mail sending library like phpMailer and don't suffer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question