PHP邮件文件发送,但不包括邮件正文
我正在向电子邮件地址发送文件。文件已正确发送,但邮件未随附。(例如,请查找随附文件) 当我发送电子邮件时,文件已正确附加,但其中没有邮件正文PHP邮件文件发送,但不包括邮件正文,php,email,Php,Email,我正在向电子邮件地址发送文件。文件已正确发送,但邮件未随附。(例如,请查找随附文件) 当我发送电子邮件时,文件已正确附加,但其中没有邮件正文 $name = $name; $email = $email; $to = "$name <$email>"; $from = "Travel Mate "; $subject = "42 Days Across Border Requirements"; $mainMessag
$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>';
}
$name=$name;
$email=$email;
$to=“$name”;
$from=“旅行伴侣”;
$subject=“42天跨境要求”;
$mainMessage=“请查找附件”;
$fileatt=“42dc form.pdf”;
$fileatttype=“应用程序/pdf”;
$fileattname=“42dayscrossborders.pdf”;
$headers='来自:info@travelmate.com.pk' . “\r\n”。
答复:info@travelmate.com.pk' . “\r\n”。
“X-Mailer:PHP/”。phpversion();
//文件
$file=fopen($fileatt,'rb');
$data=fread($file,filesize($fileatt));
fclose($文件);
//这将附加文件
$semi_rand=md5(time());
$mime_boundary=“==Multipart_boundary_x{$semi_rand}x”;
$headers.=“\n时间版本:1.0\n”。
“内容类型:多部分/混合;\n”。
“边界=\”{$mime\u boundary}\”;
$message=“42天跨境表单。\n”。
“-{$mime_boundary}\n”。
“内容类型:文本/普通;字符集=\”iso-8859-1\n“。
“内容传输编码:7bit\n”“$mainMessage”“\n”;
$data=chunk_split(base64_encode($data));
$message.=“--{$mime\u boundary}\n”。
“内容类型:{$fileatttype}\n”。
“名称=\”{$fileattname}\“\n”。
“内容处置:附件\n”。
“文件名=\”{$fileattname}\“\n”。
“内容传输编码:base64\n”。
$data。“\n\n”。
“-{$mime_boundary}-\n”;
//$message=“sdfsdfsdf”;
if(邮件($to、$subject、$mainMessage.$message、$headers)){
标题('Location:index.php?s=success');
$result='谢谢!我会与您联系';
}
你应该考虑使用像SwiftMailer这样的框架,它帮助你集中在业务逻辑而不是电子邮件的基础上,什么是主消息,什么是MasasGE?我想用它发送一个消息。但是只有文件没有接收到消息正文。如果我删除$消息,只发送消息…你的身体MIME Bou.数据分隔符不正确。请参阅IETF RFC-1341“MIME(多用途Internet邮件扩展)”第7.2.1节“多部分:通用语法”-