0

这是我用来发送邮件的 php 函数(在这里找到的,不是我的):

function send_email($to, $subject, $msg, $from, $file){

$separator = md5(time());

$eol = PHP_EOL;

$attachment = chunk_split(base64_encode($file));

$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;

$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= "<pre>".$msg."</pre>".$eol;

$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$file."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

mail($to, $subject, $body, $headers);

}

正文是正确的,但附件文件不同。我不知道为什么,但我认为它被覆盖了......

这就是我调用函数的方式:

send_email( $_POST['email'], 'Your CV file', $msg, 'admin@mydomain.com', basename( $_FILES['file']['name']) )

附件文件应由用户上传。我检查了上传的文件,和我上传的文件是一样的,但是发送后就不一样了。我不知道该怎么办。

谢谢!

4

0 回答 0