English 中文(简体)
PHP emailches
原标题:PHP email attachments

我试图寄送带有多个附件的电子邮件。

This is an example:
$uid = md5(uniqid(time()));
$header = "From: Test <test@test.com> ";
$header .= "MIME-Version: 1.0 ";
$header .= "Content-Type: multipart/mixed; boundary="" . $uid . "" ";
$header .= "--" . $uid . " ";
$header .= "Content-type:text/plain; charset=iso-8859-1 ";
$header .= "Content-Transfer-Encoding: 7bit ";
$header .= "Test Email ";
$header .= "--" . $uid . " ";
$header .= "Content-Type: text/x-csv; name="1.csv" ";
$header .= "Content-Transfer-Encoding: base64 ";
$header .= "Content-Disposition: attachment; filename="1.csv" ";
$header .= $csvfile1 . " ";
$header .= "--" . $uid . "--";
$header .= "Content-Transfer-Encoding: 7bit ";
$header .= "Test Email ";
$header .= "--" . $uid . " ";
$header .= "Content-Type: text/x-csv; name="2.csv" ";
$header .= "Content-Transfer-Encoding: base64 ";
$header .= "Content-Disposition: attachment; filename="2.csv" ";
$header .= $csvfile2 . " ";
$header .= "--" . $uid . "--";
$header .= "Content-Transfer-Encoding: 7bit ";
$header .= "Test Email ";
$header .= "--" . $uid . " ";
$header .= "Content-Type: text/x-csv; name="3.csv" ";
$header .= "Content-Transfer-Encoding: base64 ";
$header .= "Content-Disposition: attachment; filename="3.csv" ";
$header .= $csvfile3 . " ";
$header .= "--" . $uid . "--";

And I get some strange characters at the end of the csv files, something like this:
w־סֽד·ֽסמ׳fק־ןo,
‰z{­©}ךֺxn+¢”j״¶ Eט²¶*Jײֻrֵz°¶+·$j״¶ 5ל†·u+¶+‰ֻ{²װj״¶ ,

问题是什么?

感谢。

最佳回答

一些问题:

  • There should be only one new line before a boundary. You have 2.
  • You should have 2 dashes only after the last boundary.
  • There are 2 places where Content-Transfer-Encoding needs to have a new line before.
  • You may have forgotten to base64 encode your files.
  • Your code looks like the result of some terrible copy-pasting.
  • Maybe other.

正如El Yobo在评论中所说的那样,或许你应该尝试为此使用一个图书馆。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签