Last active
February 28, 2018 18:39
-
-
Save usagizmo/83eab4530c46f5a1083f14b12f665f67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 言語、文字コードを設定する | |
mb_language('uni'); | |
mb_internal_encoding('UTF-8'); | |
function map_htmlspecialchars($request) | |
{ | |
return array_map(function ($value) { | |
return is_array($value) ? | |
map_htmlspecialchars($value) : | |
htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); | |
}, $request); | |
} | |
$_POST = map_htmlspecialchars($_POST); | |
/** | |
* 送信情報 | |
*/ | |
// 内容送信先 | |
$mailTo = $_POST['email']; | |
// $mailCc = '[email protected]'; | |
// $mailCc .= ', ' . mb_encode_mimeheader('うさぎCC2') . '<[email protected]>'; | |
// $mailBcc = '[email protected]'; | |
// メールの件名 | |
$subject = '件名が入ります'; | |
// 送信主のアドレス | |
$mailFrom = mb_encode_mimeheader('うさぎ') . '<[email protected]>'; | |
// メール内容 | |
$content = <<<EOF | |
お名前: {$_POST['name']} | |
メールアドレス: {$_POST['email']} | |
お問い合わせ内容: | |
{$_POST['message']} | |
EOF; | |
/** | |
* ヘッダーの作成 | |
*/ | |
$header = "From: $mailFrom"; | |
if ($mailCc) { | |
$header .= "\n"; | |
$header .= "Cc: $mailCc"; | |
} | |
if ($mailBcc) { | |
$header .= "\n"; | |
$header .= "Bcc: $mailBcc"; | |
} | |
$success = mb_send_mail($mailTo, $subject, $content, $header); | |
if (!$success) { | |
// http_response_code(500) // php 5.4+ | |
header(' ', true, 500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment