file attachment issue to email?
My file is attached and sent with no error, but the attachment in my Inbox folder shows as follows:
// this is included in the email subject and body, so not correct file attach boundary="==Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex" This is a multi-part message in MIME format. // this is included in the email subject and body, so not correct --==Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit // this is included in the email subject and body, so not correct test message
--==Multipart_Boundary_xb46dc57fb3a58f8a859f39992cfd954ex
Content-Type: image/jpeg;
name="23.jpg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEAYABgAAD/4QC8RXhpZgAASUkqAF4AAAAEABoBBQABAAAAPgAAABsBBQAB
AAAARgAAACgBAwABAAAAAgAAADEBAgAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABAAAAUGFpbnQu
TkVUIHYzLjA4AAUAGgEFAAEAAAA+AAAAGwEFAAEAAABGAAAAKAEDAAEAAAACAAAAMQECABAAAAB
My sendemail.php code is:
<?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/59638.html
上一篇: 使用PHP在电子邮件中发送多个附件
下一篇: 文件附件问题到电子邮件?