大家帮忙指教一下!为什么我的mail发送附件收到的是0字节.
代码如下:
<?php //Send Event Order
$toaddress = '[email protected]';
$subject = 'Event order'; 
$mailcontent = '1/01.pdf';
$fileName= '01.pdf';
$body="Event order!";
$boundary = uniqid( ""); 
$headers = "From: [email protected] 
Content-type: multipart/mixed;boundary=\"$boundary\""; 
# open 
$fp = fopen($mailcontent, "r"); 
# read 
$read = fread($fp, filesize($mailcontent)); 
$read = base64_encode($read); 
$read = chunk_split($read); 
$body = "--$boundary 
Content-type: text/plain; charset=iso-8859-1 
Content-transfer-encoding: 8bit $body--$boundary 
Content-type: application/pdf; name=$fileName 
Content-disposition: attachment; filename=$fileName 
Content-transfer-encoding: base64 $read --$boundary--"; 
  
mail($toaddress, $subject, $body, $headers);
?>

解决方案 »

  1.   

    改成这样附件部分出现乱码:
    <?php //Send Event Order
    $toaddress = "[email protected]";
    $subject = "Event order"; 
    $mailcontent = "1/01.pdf";
    $fileName= "01.pdf";
    $body="Event order!";
    $boundary = uniqid( ""); 
    $headers = "Content-type: multipart/mixed;boundary= $boundary\r\n"; 
    $headers .= "From: [email protected]\r\n";
    # open 
    $fp = fopen($mailcontent, "r"); 
    # read 
    $read = fread($fp, filesize($mailcontent)); 
    $read = base64_encode($read); 
    $read = chunk_split($read); 
    $body = "--$boundary
    Content-type: text/plain; charset=iso-8859-1 
    Content-transfer-encoding: 8bit $body--$boundary 
    Content-type: application/pdf; name=$fileName
    Content-disposition: attachment; filename=$fileName 
    Content-transfer-encoding: base64 $read --$boundary--"; 
      
    mail($toaddress, $subject, $body, $headers);
    ?>