文件附件问题到电子邮件?
我的文件已附加并且没有错误地发送,但收件箱文件夹中的附件显示如下:
//这包含在电子邮件主题和正文中,因此不正确的文件附加边界=“== Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex”这是一个MIME格式的多部分邮件。 //这包含在电子邮件主题和正文中,因此不正确 - == Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex Content-Type:text / plain; charset =“iso-8859-1”Content-Transfer-Encoding:7bit //这包含在电子邮件主题和正文中,所以不正确的测试消息
--==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.0n";
$headers = "Content-Type: multipart/mixed;n" ;
$headers = " boundary="{$mimeBoundary}"";
/* Multipart Boundary above message */
$message = "This is a multi-part message in MIME format.nn" .
"--{$mimeBoundary}n" .
"Content-Type: text/plain; charset="iso-8859-1"n" .
"Content-Transfer-Encoding: 7bitnn" .
$message . "nn";
/* 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: base64nn" .
$data . "nn" .
"--{$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>";
}
?>
链接地址: http://www.djcxy.com/p/59637.html