HTML表单输入数据到我的电子邮件


html form entry data to my email

我的网站上有一个表格供人们填写,我只想在他们按下提交按钮时通过电子邮件将信息发送给我,但我正在努力使用它的 PHP。

以下是我的表格

<form action="senddata.php">
    <label for="fullname"> full name:</label><br>
    <input type="text" name="fullname" id="fullname"><br><br>
    <label for="psn">PSN</label><br>
    <input type="text" name="psn" id="psn"><br>
    <label for="email">Email:</label><br>
    <input type="text" name="email" id="email"><br>
    <label for="contact"> Contact number</label><br>
    <input type="text" name="contact" id="contact"><br>
    <label for="team">Team supported</label><br>
    <input type="text" name="team" id="team"><br>
    <input type="submit" value="SUBMIT FORM">
</form>

这就是你应该如何实现这一点。

<?php
if(isset($_POST['submit']))
{
$msg = "Full Name:".$_POST['fullname']."'n PSN:".$_POST['psn']."'n Email:".$_POST['email']."'n contact:".$_POST['contact']."'n Team:".$_POST['team'];
$msg = wordwrap($msg,70);
    $header = 'From: yourmail@yourmail.com>' . "'n";
    // send email
    mail("'".$_POST['email']."'","Your mail subject goes here",$msg,$header);
}
?>
<form action="senddata.php" method="post">
    <label for="fullname"> full name:</label><br>
    <input type="text" name="fullname" id="fullname"><br><br>
    <label for="psn">PSN</label><br>
    <input type="text" name="psn" id="psn"><br>
    <label for="email">Email:</label><br>
    <input type="text" name="email" id="email"><br>
    <label for="contact"> Contact number</label><br>
    <input type="text" name="contact" id="contact"><br>
    <label for="team">Team supported</label><br>
    <input type="text" name="team" id="team"><br>
    <input type="submit" name="submit" value="SUBMIT FORM">
</form>

您应该添加发送数据的方法。 method="post",您应该为提交按钮使用名称来检查表单是否已提交name="submit"

参考这个: php.net