0

Мне нужно было написать код для автоматической отправки нескольких выбранных файлов на указанную почту. Выбор файлов оформил через чекбоксы. При проверке выдает ошибку 500. Подскажите, в чем заключается проблема?

<?php
    $a=$_POST['a'];
    $b=$_POST['b'];
    $c=$_POST['c'];
    $d=$_POST['d'];
    $e=$_POST['e'];
    $email=$_POST['email'];
    $e=[];
    if($a!=0){
        $e[]=$a;
    }
    if($b!=0){
        $e[]=$b;
    }
    if($c!=0){
        $e[]=$c;
    }
    if($d!=0){
        $e[]=$d;
    }
    if($e!=0){
        $e[]=$e;
    }
    $files = array("fb2.rar","pdf.rar","epub.rar","txt.rar","mobi.rar");
    $body = "";
// email fields: to, from, subject, and so on
$to = $email;
$from = &quot;no-reply@someurl.ru&quot;;
$subject = &quot;test&quot;;
$message = html_entity_decode($body);
$headers = &quot;From: $from&quot;;

// boundary
$semi_rand = md5(time());
$mime_boundary = &quot;==Multipart_Boundary_x{$semi_rand}x&quot;;
$headers .= &quot;\nMIME-Version: 1.0\n&quot; . &quot;Content-Type: multipart/mixed;\n&quot; . &quot; boundary=\&quot;   {$mime_boundary}\&quot;&quot;;

// multipart boundary
$message = &quot;This is a multi-part message in MIME format.\n\n&quot; . &quot;--{$mime_boundary}\n&quot; . &quot;Content-Type: text/html; charset=\&quot;iso-8859-1\&quot;\n&quot; . &quot;Content-Transfer-Encoding: 7bit\n\n&quot; . $message . &quot;\n\n&quot;;
$message .= &quot;--{$mime_boundary}\n&quot;;

// preparing attachments
for ($x = 0; $x &lt; count($e); $x++) {
    $z=$e[$x]-1;
    $file = fopen($files[$z], &quot;rb&quot;);
    $data = fread($file, filesize($files[$z]));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $message .= &quot;Content-Type: {\&quot;application/octet-stream\&quot;};\n&quot; . &quot; name=\&quot;$files[$z]\&quot;\n&quot; .
        &quot;Content-Disposition: attachment;\n&quot; . &quot; filename=\&quot;$files[$z]\&quot;\n&quot; .
        &quot;Content-Transfer-Encoding: base64\n\n&quot; . $data . &quot;\n\n&quot;;
    $message .= &quot;--{$mime_boundary}\n&quot;;
}

// send

$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
    echo &quot;&lt;p&gt;mail sent to $to!&lt;/p&gt;&quot;;
} else {
    echo &quot;&lt;p&gt;mail could not be sent!&lt;/p&gt;&quot;;
}

?>

insolor
  • 49,104

0 Answers0