2011-01-25 8 views
0

親愛なる友人、 私は添付ファイルに問題があります。私のプロジェクトに添付ファイルがあるメール機能を使用しています。ファイルxlsをそのメールに添付しました。メールで私はそのファイル値を得ることができません、それは0kを示しています。 しかし、ローカルでそのファイルがいくつかの件のデータを持っているが、その電子メール機能を実行しながら、そのが機能していない、添付ファイルは、誰も私を助けることができる、0K大きさを持っていてください... 私のコードは以下の通りです....添付ファイル付きのメールを送信する(問題はファイルサイズが0です)

$filename = "test.xls"; 
    $path = $_SERVER['DOCUMENT_ROOT']."/path/to/Documents/"; 
    $file = $path.$filename; 

    $to = "[email protected]"; 
    $subject = 'Repairs List Report'; 

    $message = "Please find the attachment file for repairs list of Last week..."; //strip_tags($_POST['message']); 
    $attachment = chunk_split(base64_encode(file_get_contents($file))); 
    //$filename = $_FILES['file']['name']; 

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

    $headers = "From: [email protected]\r\nReply-To: [email protected]"; 
    $headers .= "MIME-Version: 1.0"; 

    $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/vnd.ms-excel; name=\"$filename\" Content-Transfer-Encoding: base64 Content-Disposition: attachment $attachment --_1_$boundary--"; 
    mail($to, $subject, $message, $headers); 
+0

使用しているコードを表示できますか?また、「受け取った添付ファイルが0 kb」という意味ですか?それは私にはっきりと分かりません。 – Piskvor

+0

あなたの質問を詳しく教えてください。いずれかが起こる可能性があります。あなたはurファイルを受け取るか、またはurファイルを電子メールで受け取らない。 ursは奇妙なケースです。 urコードを投稿してください。 – Hacker

+0

'$ file'のアクセス権を変更してみてください。 PHPはそれを読むことができますか? –

答えて

0

まず、$ messageを出力して、実際に有効なMIME形式の電子メールが生成されているかどうかを確認します。私達はちょうどあなたのコードを見ることで、特定することはできません..しかし、一つのこと:

$headers = "From: [email protected]\r\nReply-To: [email protected]"; 
$headers.= "MIME-Version: 1.0"; 

は次のようになります。

$headers = "From: [email protected]\r\nReply-To: [email protected]\r\n"; 
$headers.= "MIME-Version: 1.0"; 

さてあなたは、あなたのメッセージ内のすべての改行を入れるのを忘れ:

$body ="This is a multi-part message in MIME format. (preamble)\r\n"; 
$body.="--_1_$boundary\r\n"; 
$body.="Content-Type: multipart/alternative; boundary=\"_2_$boundary\"\r\n"; 
$body.="--_2_$boundary\r\n"; 
$body.="Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; 
$body.="Content-Transfer-Encoding: 7bit\r\n"; 
$body.="\r\n"; 
$body.="$message\r\n"; 
$body.="--_2_$boundary--\r\n"; 
$body.="--_1_$boundary\r\n"; 
$body.="Content-Type: application/vnd.ms-excel; name=\"$filename\"\r\n"; 
$body.="Content-Transfer-Encoding: base64\r\n"; 
$body.="Content-Disposition: attachment\r\n"; 
$body.="\r\n"; 
$body.="$attachment\r\n"; 
$body.="--_1_$boundary--"; 

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

私は何かを逃したのかどうかはわかりませんが、これから始めることができます。最後に、作成したクラス、omimeを使用すると、mimeメールを簡単に作成できます。