正如我在标题中描述的那样,当我尝试使用附件发送邮件来自php mail()函数时,它还在正文中显示内容类型。
以下是我的代码::
$file_tmp_name = $files['file']['tmp_name'];
$file_name = $files['file']['name'];
$file_size = $files['file']['size'];
$file_type = $files['file']['type'];
$file_error = $files['file']['error'];
$handle = fopen($uploaded_file_path, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("somestring");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: mail@website.com\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = \"$boundary\"\r\n\r\n";
//plain text
$body = "--$boundary\r\n";
$body.= "My Body Content
Regards
Team Web.\r\n\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=".$file_name."\r\n";
$body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
$sentMail = @mail($mailto, $subject, $body, $headers);