2011-12-19 11 views
2

私はhtmlメールを作成しましたwelcome.tplそのファイルをメッセージの本文として送信するためにはどのようなPHPメールメソッドを使用する必要がありますか? HTMLメールテンプレートファイルとPHPの処理

これに先立ち、私は変数にHTMLとテキストを使用して含めてきた
$text_content.= "\r\n"; 
$text_content.= "--------------------------------\r\n"; 
$html_content.= "</body></html>"; 

$mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x'; 

$headers = "MIME-Version: 1.0\r\n"; 
$headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n"; 
$headers.= "Content-Transfer-Encoding: 7bit\r\n"; 

$body = "--$mime_boundary\n"; 
$body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n"; 
$body.= "Content-Transfer-Encoding: 7bit\n\n"; 
$body.= $text_content; 
$body.= "\n\n"; 

$body.= "--$mime_boundary\n"; 
$body.= "Content-Type: text/html; charset=\"UTF-8\"\n"; 
$body.= "Content-Transfer-Encoding: 7bit\n\n"; 
$body.= $html_content; 
$body.= "\n\n"; 
$body.= "--$mime_boundary--\n"; 

$headers.= 'From: So <[email protected]>' . "\r\n"; 
$headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n"; 
$headers.= 'Date: '.date('n/d/Y g:i A')."\r\n"; 
$headers.= 'Reply-To: So <[email protected]>' . "\r\n"; 

mail($en['email'], $subject, $body, $headers); 

私は$body = file_get_contents();のようなものを使用し、mail();最善の方法であるべきか?

+0

使用しているテンプレートライブラリhttp://developer.postmarkapp.com/developer-libs.html#php-5のいくつかを見てみましょう:消印付き

、あなたはこのような何かを行うことができますか? welcome.tplとメール機能の重要な部分を表示できますか? – Jomoos

+0

@Jomoos私の現在のmail()関数のスニペットを追加しました。welcome.tplについては、必要な電子メールのみを使用している基本的なhtmlのみ受け入れ可能なhtml/css – acctman

答えて

2

次のコードを使用します。

// HTMLメール

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 

を送信するときは、必ずコンテンツタイプを設定して、あなたも含めることができる //複数のヘッダ

$headers .= 'From: <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 

と使用

$body = file_get_contents(); 

とメール機能でメールを送信する:

mail($en['email'], $subject, $body, $headers); 
2

を私は次のことを示唆している:

あなたのテンプレートの拡張子.tplを使用しているので、私はあなたがテンプレートとしてのSmartyを実行していると仮定していますエンジン?

もしそうでなければ、単にfile_get_contents()を使うことができます。

$template = file_get_contents('template.tpl'); 
$template = str_replace('{name}', 'Sean Nieuwoudt', $template); 
$template = str_replace('{email}', '[email protected]', $template); 
... 
etc 

単純にmail()機能を使用して電子メールを送信します。

Postmarkappのようなものを使用して電子メールを送信する方法があります。 mail()が受信者のスパムフォルダ(特に共有ホスティング環境で動作している場合)になる可能性がある場所での配信が保証されます。

Mail_Postmark::compose() 
    ->addTo('[email protected]', 'Jane Smith') 
    ->subject('Subject') 
    ->messagePlain($template) 
    ->send(); 

が自由に利用できるPHP-消印クラス