2016-09-14 3 views
0

PHPでhtml/html5メールを送信したいと思います。私は、私がユーザーに送る予定の電子メールメッセージを持つhtmlテンプレートを持っています。あなたが含ま前に変数を設定する必要がmailservice.phpPHPでhtml/html5テンプレートメールを送信するには?

/* getting the content from te default-message.html file*/ 
ob_start(); 
include('default-message.php'); 
$message = ob_get_contents(); 
ob_end_clean(); 

$name = "John"; 
$to = "[email protected]"; 
$subject = "Hello"; 

$headers .= 'From: Me <[email protected]>' . "\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

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

あなたはどんな特有の問題を抱えていますか? – Blake

+2

円形の 'include'を作成したようです。 –

+0

@Blake拡張ファイルを.htmlに変更すると電子メールが送信されますが、変数$ nameはコンパイルされません。PHPを使用していません... – que1326

答えて

1

-

HTMLテンプレートからデフォルト-message.php

<?php include 'mailservice.php'; ?> 
<div> 

    <h3>Dear <?php echo $name; ?>,</h3> 

    <p>I send you this custom message!!</p> 

</div> 

PHPテンプレートスクリプトなので、展開されますd。テンプレートが実行されるとき。それは他を含む各スクリプトで前後に移動しますので、

ob_start(); 
$name = "John"; 
$to = "[email protected]"; 
include('default-message.html'); 
$message = ob_get_contents(); 
ob_end_clean(); 

$subject = "Hello"; 

$headers .= 'From: Me <[email protected]>' . "\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

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

また、default-message.htmlは、<?php include 'mailservice.php'; ?>を含めることはできません。

+0

はい、返信と説明のためにありがとうございました! – que1326

関連する問題