HTMLだけではできません。PHPソリューションに固執する場合は、試してください
<?php
if(isset($_POST['send'])) //check the submit button was pressed
{
//get variables from POST array. Remember we specified POST method
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
//set up headers
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//send the email and save the result
$result = mail($to, $subject, $message, $headers);
//was it sent?
if($result)
{
echo "Successfuly sent the email";
}
else
{
echo "An error has occured";
}
}
?>
<hr>
<form method="POST">
To: <input type="text" name="to"> <br>
Subject: <input type="text" name="subject"> <br>
Text: <textarea name="message"></textarea><br>
<input type="submit" value="Send" name="send">
</form>
同じファイルであるため、フォームが指す場所を指定する必要はありません。それ以外の場合は
<form action="somefile.php" method="POST">
メソッド POST を指定する必要がありますが、そうしないと、デフォルトですべてのデータが GET 経由で送信されます。
PHP には、電子メールの送信に使用されるメール関数がありますhttp://php.net/manual/en/function.mail.php
メールの配信が正常に受け入れられた場合は TRUE を返し、それ以外の場合は FALSE を返します。
メールが送信されたかどうかを確認し、対応するメッセージを印刷します。次に、結果に関係なく、メッセージ フォームを出力します。