2011-11-25 20 views
1

PHPでHTMLメールを送信しようとしていますが、電子メールプログラムの電子メールのソースコードが常に表示されます。しかし、htmlの電子メールをHTMLとして表示し、電子メールのコンテンツとしてソースコードを表示しないでください。sendmailでhtml電子メールを送信/送信しようとしていますが、電子メールのソースコードを表示しています

私はこのように私のメール送信:

$fd = popen("/var/qmail/bin/sendmail -t","w") or die("Couldn't Open Sendmail"); 
    fputs($fd, "To: ".$to2." \n"); 
    fputs($fd, "From: \"Test <[email protected]>\" \n"); 
    fputs($fd, "Subject: ".$subject." \n"); 
    fputs($fd, "X-Mailer: PHP5 \n"); 
    fputs($fd, "Mime-Version: 1.0 \n"); 
    fputs($fd, " \n"); 
    fputs($fd, "--".$mime_boundary.""); 
    fputs($fd, "Content-Type: text/html; charset=\"utf-8\"; boundary=\"".$mime_boundary."\" \n"); 
    fputs($fd, "Content-Transfer-Encoding: quoted-printable \n"); 
    fputs($fd, " \n"); 
    fputs($fd, $sendmail_body." \n"); 
    fputs($fd, "".$mime_boundary."--"); 
    pclose($fd); 

htmlファイルの内容は次のようになります。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Test</title> 
<style type="text/css"> 
body { font: normal 12px Verdana, Arial, Helvetica, sans-serif; } 
</style> 
</head> 
<body> 
</body> 
</html> 

それは今働い:

$ FD = popenの( "/ var/qmail/bin/sendmail -t"、 "w")またはdie( " Sendmail"をオープンできませんでした。 fputs($ fd、 "To:"。$ to1。 "\ n"); fputs($ fd、 "From: \"テスト\ "\ n"); fputs($ fd、 "Subject:"。$ subject。 "\ n"); fputs($ fd、 "X-Mailer: PHP5 \ n"); fputs($ fd、 "Mime-Version:1.0 \ n"); fputs($ fd、 "Content-Type:multipart/alternative; boundary = \" "。$ mime_boundary。" \ "\ n"); fputs($ fd、 "\ n"); fputs($ fd、 " - "。$ mime_boundary。 "\ n"); fputs($ fd、 "Content-Type: text/html; charset = \" utf-8 \ "\ n"); fputs($ fd、 "コンテンツ転送エンコーディング:quoted-printable \ n"); fputs($ fd、 " \ n"); fputs($ fd、$ sendmail_body。 "\ n"); fputs($ fd、 " - "。$ mime_boundary。 " - \ n"); pclose($ fd);

私のhtmlファイルの最初の行は空です。または、htmlコンテンツの前に\ nを追加します。

+0

私はいくつかの行を忘れてしまったので、私の質問を編集する必要がありました –

答えて

2

ことを願っています:

$headers = "From: Example <[email protected]>\r\n 
    MIME-Version: 1.0\r\n 
    Content-Type: multipart/alternative; boundary={$mime_boundary}\r\n 
    X-Mailer: PHP5"; 

$message = "This is a MIME-Message. If you can read this your client does not support the MIME format.\r\n 
\r\n 
{$mime_boundary}\r\n 
Content-Transfer-Encoding: quoted-printable\r\n 
Content-Type: text/plain; charset=utf8;\r\n 
\r\n 
Text Content encoded in quoted printable 
\r\n 
\r\n 
{$mime_boundary}\r\n 
Content-Transfer-Encoding: quoted-printable\r\n 
Content-Type: text/html;charset=utf8;\r\n 
\r\n 
HTML Content encoded in quoted printable 
\r\n 
--{$mime_boundary}"; 

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

sendmailのパスとパラメータがphp.iniで正しく設定されていれば、これはmultipart/alternativeの形式でsendmail経由でメールを送信します。

+0

\ nまたは\ r \ nを示していますか?あなたは私を混乱させている –

+0

\ nはUNIXのような方法で、Windowsは\ r \ nとMac OSだけを\ r - so \ r \ nはすべてのシステムで改行を生成します。\ r \ nまたは\ nメールの文脈に違いはないはずですが、時には彼らはそうするでしょう... –

+0

そのUnixマシン/ WebサーバーはLinux上で動作していますので、私はいらないですか?時々?だから私は間違いなく\ r \ nを使うべきですか? –

0
fputs($fd, "X-Mailer: PHP5 \n\n"); 

ヘッダーの終了の兆候であるため、2番目の\ nを削除してみます。

+0

それは動作しますか? –

1

これが私の仕事:

 
<?php 
$message=<<<EOL 
--frontier 
Content-type: text/plain; charset=UTF-8 
Content-Transfer-Encoding: 7bit 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Test</title> 
<style type="text/css"> 
body { font: normal 12px Verdana, Arial, Helvetica, sans-serif; } 
</style> 
</head> 
<body> 
</body> 
</html> 
--frontier-- 
EOL; 

$fd = popen("/var/qmail/bin/sendmail -t","w") or die("Couldn't Open Sendmail"); 

fputs($fd, "To: ".$to." \n"); 
fputs($fd, "From: \"Example\" <[email protected]> \n"); 
fputs($fd, "Subject: ".$subject." \n"); 

fputs($fd,"MIME-Version: 1.0\n"); 
fputs($fd,"Content-type: multipart/alternative; boundary=\"frontier\"\n\n"); 
fputs($fd,"This is a message with multiple parts in MIME format.\n"); 

fputs($fd, $message); 
pclose($fd); 
?> 

を、私はいくつかのクライアントがHTMLメールをサポートするか、単にプレーンテキストを好まないので、あなたがマルチパートを送ることを検討すべきだと思う、それは役に立ち

+0

とhtmlファイルの私のdoctype?私はTransfer-Encoding、Content-Typeのようなこれらすべてのものを今変更しなければなりません。 –

+0

それを試しました(私はhtmlファイルでdoctypeを使用しますが)、受信メールは空です(outlook、プレーン空)とiphoneにそれはソースコード –