とりあえずdatabaseから作ります。
mysql> create database if not exists send_mail;
Query OK, 1 row affected (0.30 sec)
続いて、table
mysql> create table send_mail.html(
-> 'id' int AUTO_INCREMENT,
-> 'html' MEDIUMTEXT,
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id' int AUTO_INCREMENT,
'html' MEDIUMTEXT,
)' at line 2
あれ、シングルクオテーションは必要ないか。。
sql文を編集します。
create table send_mail.html(
id int AUTO_INCREMENT NOT NULL PRIMARY KEY,
html MEDIUMTEXT
);
OK! insertしていきましょう♪
mysql> INSERT INTO send_mail.html (html)
-> VALUES ('タイトルが入ります');
Query OK, 1 row affected (0.46 sec)
mysql> select * from html;
+----+--------------------------------------------+
| id | html |
+----+--------------------------------------------+
| 1 | タイトルが入ります |
+----+--------------------------------------------+
1 row in set (0.12 sec)
うお!きたきたきたきた!
titleタグ以外のタグを入れてみます。
mysql> INSERT INTO send_mail.html (html)
-> VALUES ('
');
Query OK, 1 row affected (0.53 sec)
mysql> select * from html;
+----+-----------------------------------------------+
| id | html |
+----+-----------------------------------------------+
| 1 | タイトルが入ります |
| 2 |
|
+----+-----------------------------------------------+
2 rows in set (0.09 sec)
おうおう。OKだ。
pdoでmysqlからfetchする。
<?php
try {
$pdo = new PDO('mysql:host=localhost;dbname=send_mail;charset=utf8','root','',
array(PDO::ATTR_EMULATE_PREPARES => false));
} catch (PDOException $e) {
exit('データベース接続失敗。'.$e->getMessage());
}
$stmt = $pdo->query("SELECT * FROM html where id = 2");
while($row = $stmt -> fetch(PDO::FETCH_ASSOC)){
$img = $row["html"];
echo $img;
}

おいおいおい!!!!
それでは、ひっぱてきたhtmlタグをmb_send_mailで送信したいと思います。
<?php
try {
$pdo = new PDO('mysql:host=localhost;dbname=send_mail;charset=utf8','root','',
array(PDO::ATTR_EMULATE_PREPARES => false));
} catch (PDOException $e) {
exit('データベース接続失敗。'.$e->getMessage());
}
$stmt = $pdo->query("SELECT * FROM html where id = 2");
while($row = $stmt -> fetch(PDO::FETCH_ASSOC)){
$img = $row["html"];
}
mb_language('Japanese');
mb_internal_encoding("UTF-8");
$header_info="From: admin@example.com"."\nContent-Type: text/html;charset=ISO-2022-JP\nX-Mailer: PHP/".phpversion();
$insert = "差し込み文章";
$body = <<< EOM
<!DOCTYPE>
<html lang="ja">
<head>
</head>
<body>
Look!<br>
<strong style="color:red;">apple</strong><br>
{$img}<br>
{$insert}が入ります。
</body>
</html>
EOM;
print $body;
mb_send_mail("hogehoge@hoge.com",'test',$body,$header_info);
?>
おおおおおおお、簡単だが、おおよその仕組みはわかった。

次は実際に届いてるHTMLメールのソースコードを見てみよう。