将文件上传到数组

时间:2014-04-16 19:40:44

标签: php html email-attachments

我正在尝试创建一个php脚本来上传多个文件并将其作为附件发送电子邮件。我能够上传文件,并发送电子邮件。它如何只附加1封电子邮件。我真的无法弄清楚为什么它只附上一封电子邮件......但我想我已经开始在过去几个小时盯着这段代码获得隧道视野了。一双新鲜的眼睛看着它会很棒!

<?php
    if(isset($_POST['submit']))
    {
        //Deal with the email
        $to = 'to email';
        $subject = 'PDFs';

        $message = strip_tags($_POST['message']);
        $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
        $filename = $_FILES['file']['name'];

        $boundary =md5(date('r', time())); 

        $headers = "From: fromemail\r\nReply-To: fromemail";
        $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

        $message="This is a multi-part message in MIME format.

--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$message

--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment
--_1_$boundary--";

        mail($to, $subject, $message, $headers);
    }
?>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Request Quote</title>
</head>

<body>


<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<INPUT TYPE="hidden" NAME="redirect" VALUE="http://localhost/pdf3.php">
    Select PDF(s): <input type="file" name="file" multiple>
    <p>  <sup> Hold CTRL to select multiple files. </sup> </p>

<p><label for="message">Message</label> <textarea name="message" id="message" cols="20" rows="8"></textarea></p>
<p><input type="submit" name="submit" id="submit" value="send"></p>
</form>
</body>
</html>

0 个答案:

没有答案