Отправка файла PHP Mail, но тело сообщения не включено - PullRequest
0 голосов
/ 30 мая 2018

Я отправляю файл на адрес электронной почты, файл отправляется правильно, но сообщение не прикрепляется к нему.(например, пожалуйста, найдите прикрепленный файл).

когда я отправляю сообщение электронной почты, файл прикреплен правильно, но в нем нет тела сообщения, может кто-нибудь, пожалуйста, помогите

$name        = $name;
    $email       = $email;
    $to          = "$name <$email>";
    $from        = "Travel Mate ";
    $subject     = "42 Days Across Border Requirements";
    $mainMessage = "Kindly Find the Attached File";
    $fileatt     = "42dc-form.pdf";
    $fileatttype = "application/pdf";
    $fileattname = "42DaysAcrossBorders.pdf";
    $headers = 'From: info@travelmate.com.pk' . "\r\n" .
    'Reply-To: info@travelmate.com.pk' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    // File
    $file = fopen($fileatt, 'rb');
    $data = fread($file, filesize($fileatt));
    fclose($file);

    // This attaches the file
    $semi_rand     = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers      .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";
    $message = "42 Days Across Borders Form.\n" .
    "-{$mime_boundary}\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\n" .
    "Content-Transfer-Encoding: 7bit\n" . $mainMessage  . "\n";

    $data = chunk_split(base64_encode($data));
    $message .= "--{$mime_boundary}\n" .
    "Content-Type: {$fileatttype};\n" .
    " name=\"{$fileattname}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$fileattname}\"\n" .
    "Content-Transfer-Encoding: base64\n" .
    $data . "\n\n" .
    "-{$mime_boundary}-\n";
    //$message = "sdfsdfsdf ";

    if(mail($to,$subject, $mainMessage.$message, $headers)){
        header('Location:index.php?s=success');
        $result='<div class="alert alert-success col-sm-12">Thank You! I will be in touch</div>';
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...