メールを送信するサンプルコード。メール本文はSmartyで定義。
1 2 3 |
Hello, {$recipient}. How are you? See you soon! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
$to = "hanako@example.com"; $from = "taro@example.com"; $bcc = "takeo@example.com"; $return = "support@example.com"; $subject = "Greetings"; $smarty = new Smarty(); $smarty->assign('recipient, 'Taro'); $body = $smarty->fetch('email.tpl'); mb_language("ja"); mb_internal_encoding("UTF-8"); $subject = mb_convert_encoding($subject, "ISO-2022-JP", "AUTO"); $subject = mb_encode_mimeheader($subject); $headers = "MIME-Version: 1.0 \n"; $headers .= "From: " . $from . "\n"; $headers .= "Bcc: " . $bcc . "\n"; $parameters = "-f " . $return; if (!mb_send_mail($to, $subject, $body, $headers, $parameters)) { echo "mb_send_mail() failed.\n"; return false; } return true; |
Smartyを使わないサンプルは以下。
[PHP] メールを送信する | プログラミング雑記
https://www.84kure.com/blog/?p=196