私は持っている。一般的な HTML を使用したフォームはほとんどありません。
1 つのフォームは、データベース内の連絡先に電子メールを送信します。
##!CONTACT_FORENAME!## のようなものを使用すると、データベースの連絡先の名前 (連絡先テーブルの名前列) に置き換えられるようにするにはどうすればよいですか?
あなたはテンプレートを持っています
$string_template = '
Hello [username],
.....
';
次に、文字を単純に置き換えます。
$message = strtr($template, array('[username]' => $user_name_from_dtb));
$body='some text with [variable]';
$regex = "/\[.+?\]/"; // if not use brakets, change this.
if(preg_match_all($regex, $body, $matches, PREG_PATTERN_ORDER)) {
foreach ($matches[0] as $key => $match) {
$mvar=substr($match,1,strlen($match)-2); // get the variable name
$value='this is a real value'; // get the variable value from db;
$body=preg_replace("#\[".$mvar."\]#s",$value,$body);// replace
}
}