我的文件已附加并发送,没有任何错误,但我的收件箱文件夹中的附件显示如下:
//这包含在电子邮件主题和正文中,所以不正确 file attach boundary =“== Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex” 这是MIME格式的多部分消息。 //这包含在电子邮件主题和正文中,所以不正确 - == Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex 内容类型:text / plain;字符集= “ISO-8859-1” 内容传输编码:7位 //这包含在电子邮件主题和正文中,所以不正确 测试消息
--==Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex Content-Type: image/jpeg; name="23.jpg" Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAQEAYABgAAD/4QC8RXhpZgAASUkqAF4AAAAEABoBBQABAAAAPgAAABsBBQAB AAAARgAAACgBAwABAAAAAgAAADEBAgAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABAAAAUGFpbnQu TkVUIHYzLjA4AAUAGgEFAAEAAAA+AAAAGwEFAAEAAABGAAAAKAEDAAEAAAACAAAAMQECABAAAAB
我的sendemail.php代码是:
<?php
$headers= "MIME-Version: 1.0";
$headers= "Content-type: text/plain; charset=iso-8859-1";
$headers= "From: $_POST[name] <$_POST[email]>";
$headers= $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
/* GET File Variables */
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];
if (file_exists($tmpName)) {
/* Reading file ('rb' = read binary) */
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);
/* a boundary string */
$randomVal = md5(time());
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";
/* Header for File Attachment */
$headers = "\nMIME-Version: 1.0\n";
$headers = "Content-Type: multipart/mixed;\n" ;
$headers = " boundary=\"{$mimeBoundary}\"";
/* Multipart Boundary above message */
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mimeBoundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
/* Encoding file data */
$data = chunk_split(base64_encode($data));
/* Adding attchment-file to message*/
$message .= "--{$mimeBoundary}\n" .
"Content-Type: {$fileType};\n" .
" name=\"{$fileName}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mimeBoundary}--\n";
}
$to_user = "nur_Selam@yahoo.com";
$flgchk = mail($to_user, $subject, $message, $headers);
//require_once ('./includes/functions_mail.php');
if ($flgchk) {
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"2;url=forwardtoother.php?page=sender.html\">";
echo "Done, <br>";
echo "Redirecting you to your <a href=\"?page=sender.html\">Inbox</a>";
}
else
{
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"2;url=forwardtoother.php?page=sender.html\">";
echo "Failed to send email, <br>";
echo "Redirecting you to your <a href=\"?page=sender.html\">Inbox</a>";
}
?>