1

I have a form on my website for people to fill out and I just want the information to be sent to me in an email when they press the submit button but i'm struggling with the PHP for it.

below is the form I have

<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>
noushid p
  • 1,453
  • 5
  • 16
  • 29

1 Answers1

1

This is how you should implement this.

<?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>

you should add method for send your data. method="post"and you should use a name for your submit button to check whether your form is submitted or notname="submit"

refer this: php.net

isuruAb
  • 2,202
  • 5
  • 26
  • 39