你不能只使用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: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\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">
Altough必须指定POST方法,否则所有的数据将通过GET默认发送
PHP有用来发送电子邮件邮件功能http://php.net/manual/en/function.mail.php
如果邮件已成功接收传送,则返回TRUE,否则返回FALSE 。
我们检查电子邮件是否被发送并打印相应的消息。然后,不管结果如何,我们都会打印出消息表单。
你打算做是正确的方式。将表单提交给PhP脚本,处理该PhP脚本中的POST变量并发送邮件,然后重定向至确认页面。 –
Someattribute应该是action ='sendmail.php'和你的正确轨道。 – jeff
不要忘记表单中的action ='post'属性。 – notknown7777