2012-01-31 3 views
0

はこちら(すべての)コードです:PHPの電子メールスクリプトは、HTMLバージョンまたは添付ファイル拡張子を生成しません。何が悪かったのか?

<?php 
/* 

      WHITE SPACE MATTERS IN THIS DOCUMENT 

*/ 
include("_php/ChromePhp.php"); 
    // define receiver of email 
$to = "[email protected]"; 
    // define subject of email 
$subject = "<--== KABAM! HTML Email from WR! ==-->"; 
    // define message to send. use /n for linebreaks 
//$message = 'This is the message. Read it. Love it.'; 
    // create a boundary string. it must be unique! 
$uniqID = md5(date('r', time())); 
    // define the headers. separated by \r\n 
$headers = "From: some dude" . "\r\n"; 
$headers .= "Reply-To: nobody" . "\r\n"; 
$headers .= "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uniqID."\""."\r\n"; 
    // read the attachment into a string, encode it and then 
    // split it into smaller chunks 
$attachment = chunk_split(base64_encode(file_get_contents('./_dox/pdftmp/emailTESTER.zip'))); 
    // define the body of the message 
ob_start(); // turn on output buffering 
?> 
--PHP-mixed-<?php print $uniqID; ?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php print $uniqID; ?> 

--PHP-alt-<?php print $uniqID; ?> 
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 

This is the TEXT email. 
Nothing but pure text. not really fun... 

--PHP-alt-<?php print $uniqID; ?> 
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 

<h1>This is the HTML test email.</h1> 
<h3>Read it. Love it.</h3> 
<p>this is all HTML. without any CSS, mind you...</p> 

<?php include("_php/formEmail.php"); ?> 

--PHP-alt-<?php print $uniqID; ?>-- 

--PHP-mixed-<?php print $uniqID; ?> 
Content-Type: application/zip; name="emailTESTER.zip" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

<?php print $attachment; ?> 
--PHP-mixed-<?php print $uniqID; ?>-- 

<?php 
    // copy current buffer contents into $message then delete 
    // the contents of the output buffer 
$message = ob_get_clean(); 
    // send the email 
$mail_sent = @mail($to, $subject, $message, $headers); 
    // display a message depending on mail_sent status 
print $mail_sent ? "Mail Sent: ".$uniqID : "Mail Failed: ".$uniqID; 
?> 

と、これは電子メールクライアントに飛び出すものです:代わりであることの、

This is the TEXT email. 
Nothing but pure text. not really fun... 

--PHP-alt-a0d18dbf6c6ec8fb30c47adc84234c75Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 

<h1>This is the HTML test email.</h1> 
<h3>Read it. Love it.</h3> 
<p>this is all HTML. without any CSS, mind you...</p> 


--PHP-alt-a0d18dbf6c6ec8fb30c47adc84234c75-- 

添付ファイルを(...レンダリングされません)」 emailTESTER.zip "は単に「パート2」であり、拡張子はありません。私が '.zip'を追加すると、正しい内容の適切なアーカイブ(誤っているにも関わらず)になります...

私は境界線を3回チェックしました。正しく設定されていると思います。私が考えることができるのはContent-Type宣言の中の何かになるだろう...しかし、それがあれば、私はそれが何であるかについては空白だ... "PHP email HTML blah blah "と洞察力を貸している間に、それらのどれも私の奇妙な双子のことに触れなかった。 narf

so。私は何を取りこぼしたか?なぜそれが正しく/完全に動作していないのですか?

TIA。

WR!

+0

これを試してください '$ headers。= 'Content-type:text/html; charset = UTF-8 '。 "\ r \ n"; ' – k102

+0

私はそれに渦を立てます。直感が正しく私を指摘したように見える!トレイルの最後に空白を記入してくれてありがとう。 :) – WhiteRau

+0

が機能しませんでした。クレイアップ。とにかくありがとう。 :) – WhiteRau

答えて

1

ホイールを改造しないでください。既存のメールクラスを使用します。 PHPMailerは優れています。

+0

リンクに感謝しますが、私は学問的な練習としてこれをやっていました。それをFeynmanのコーディング手法と呼んでください。 :) – WhiteRau

+0

私はクラスを見ました。いいね私は質問があります:file_get_contentsはソースHTML/PHPファイルのCSSファイルを処理しますか? – WhiteRau

関連する問題