そのため、From: in a form to email スクリプトで送信者の氏名を表示するのに問題があります。
私はこれを持っています:
<?php
if(!$_POST) exit;
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$comments = $_POST['comments'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
}
$address = "example@example.com, example@example.com";
$e_subject = '' . $name . ' has confirmed their attendance.';
$e_body = "$name blah blah blah blah" . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "Please do not reply to this email";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $name" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Success!</h1>";
echo "<p>Thank you</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
名前フィールドに単語/名前が1つだけ入力されている場合は機能しますが、2つ以上の単語が表示されるとすぐに表示されます(不明な送信者)。
名前を 2 つのフィールドに分割することもできますが、実際にはそうしたくありません。
私は何を間違っていますか?
ありがとう!