我试图通过电子邮件发送一个带有php的zip文件。 一切都适用于gmail和apple邮件,但是当我用hotmail打开电子邮件时,代码显示为纯文本。 这是代码:
<?php
ini_set('display_errors', '1');
ini_set('error_reporting', E_ALL);
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$count = 1;
foreach($_POST as $key => $value)
{
/*make Image*/
if($key == "mail")
{
continue;
}
$content = file_get_contents($_POST[$key]);
$fp = fopen('SHRINK/image'.$count.'.jpg', 'w');
fwrite($fp, $content);
$count++;
}
$fp2 = fopen("SHRINK/test.txt","w");
fwrite($fp2,"COPYRIGHT - DOMINIK SCHATZ");
//zip files
$zip = new ZipArchive;
$res = $zip->open("SHRINK/SHRINK.zip", ZipArchive::CREATE);
if ($res === TRUE)
{
$zip->addGlob("SHRINK/*");
} else {
echo 'Fehler beim erstellen der Zip-datei';
}
$zip->close();
$myMail = "myMail@testmail.mymail";
$name = "testname";
$tel ="000000";
$adr = "ADRESSE";
$email = filter_var($_POST["mail"], FILTER_VALIDATE_EMAIL);
if(!$email)
{
echo json_encode("die emailadresse ist nicht gültig");
exit();
}
//prepare zip for sending
$fileatt_type = "application/zip"; // File Type
$fileatt_name = 'SHRINK.zip'; // Filename that will be used for the file as the attachment
$file = fopen("SHRINK/SHRINK.zip",'rb');
$data = fread($file,filesize("SHRINK/SHRINK.zip"));
fclose($file);
//define headers and stuff
$headers = "From: ".$email."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-Type: multipart/mixed\n" ;
$headers .= "Reply-To: ".$myMail. "\r\n";
$headers .= "CC: ".$name;
$intro = "AUTOMATISCH GENERIERTE NACHRICHT<br><br>";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$data = chunk_split(base64_encode($data));
$message = "--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n";
$message .= "<head></head><body>NAME: ".$name."<br>EMAIL: ".$myMail."<br>TELEFON: ".$tel."<br>
ADRESSE: ".$adr."<br>";
$message .= "\r\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// string breaks after 60 chars
$message = wordwrap($message, 60);
$outro = "outro";
//SEND EMAIL
if(@mail($email, "Nachricht von ".$name, $intro.','.$message.','.$outro , $headers))
{
// Send
$name = "SHRINK";
//close
fclose($fp);
fclose($fp2);
//delete packed filesize
unlink('SHRINK/test.txt');
unlink('SHRINK/SHRINK.zip');
/*clear everything from tmp folder(just to be sure)*/
$filesToDelete = $files = glob('SHRINK/{,.}*', GLOB_BRACE);
foreach($filesToDelete as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}
echo json_encode("Ihr Bild wurde erfolgreich an ".$_POST["mail"]." versendet");
exit();
}
}
?>
这是我收到的电子邮件:
AUTOMATISCH GENERIERTE NACHRICHT<br><br>,--==Multipart_Boundary_xa05228000753f946057d2d37ce1c2ea9x
Content-Type:text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<head></head><body>NAME: testname<br>EMAIL:
myMail@testmail.mymail<br>TELEFON: 000000<br>
ADRESSE: ADRESSE<br>
--==Multipart_Boundary_xa05228000753f946057d2d37ce1c2ea9x
Content-Type: application/zip;
name="SHRINK.zip"
Content-Transfer-Encoding: base64
UEsDBBQAAAAIAEujQkb088Q74xYAABQXAAARAAAAU0hSSU5LL2ltYWdlMS5qcGclWAVck18XNpBO
QbpFGukBQ2LU6B4iKI10jhAQEHEgHWOSktISk5EKCNINQ+mW7m74Xv/ffu/ebe/v3nvOvec553nO
InS1oSSE9IR37twhUVNV0gc+bYC3Aj4ucM+hgQffuUM9paYEMXyTsZ3xQjd9HVXpLS0qMaNWkph5
I6095VFbSKJq9eij8jvyhwp8Cpe4k3dDPsTLfw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uJEl8EZHgVSObUoYM7WNr8Q+rH17w3Jz
SU6IIGOa0s5UYp9Q77KU+3V961tDqW9gUIWKn7takcAza22+3naTCr55Ji4u/lHJNPkBc/v+UicL
uCaw5nGCKnPR7s1+RdBx6dtlPvOFCbus5bP9pasd32ZFVvKtqmPbuN4LiWCEKkdrNk9usNcGerwm
VV3mKjYwR1dVT4/i9oF8HaPxi/f3ZO4ALzVlbaVyBYv3/wNQSwMEFAAAAAgAS6NCRjcKg9UcAAAA
GgAAAA8AAABTSFJJTksvdGVzdC50eHRz9g+IDPJ09whR0FVw8ff19PP0Vgh29nAMiQIAUEsBAgAA
FAAAAAgAS6NCRvTzxDvjFgAAFBcAABEAAAAAAAAAAAAAAAAAAAAAAFNIUklOSy9pbWFnZTEuanBn
UEsBAgAAFAAAAAgAS6NCRjcKg9UcAAAAGgAAAA8AAAAAAAAAAAAAAAAAEhcAAFNIUklOSy90ZXN0
LnR4dFBLBQYAAAAAAgACAHwAAABbFwAAAAA=
--==Multipart_Boundary_xa05228000753f946057d2d37ce1c2ea9x--
,outro
编辑:我添加了整个php脚本
答案 0 :(得分:0)
您没有将Content-Type: multipart/mixed
添加到标头中。你现在获得的一行不是将它添加到$ header(它们现在只是“xxxx”行)。
我怀疑你想这样做:
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$header .= "Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$data = chunk_split(base64_encode($data));
请注意“Content-Type ....
之前的$header .=
您还可能希望在介绍和outro之间添加一些额外的换行符(而不是,
):
if(@mail($email, "Nachricht von ".$name, $intro."\n".$message."\n".$outro , $headers))
之后,任何邮件客户端都应正确解释您的多部分。
如果您通过POST传递多个图像,也会出现一个小问题。你做一个$ fp = fopen(在循环中但没有关闭前一个。所以有很多文件打开,其中最后一个是在$ fp变量中