我正在将文件发送到正确发送的电子邮件地址文件,但邮件未附加。 (例如,请找到附件)。
当我发送电子邮件文件正确附加但没有邮件正文时,任何人都可以请帮助
$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>';
}