I am trying to create a contact form that sends an email to my email account(Google). I found a nice tutorial, copied the code and replaced some of it with what I need (Used a tutorial because I am completely green to PHP and this area.) I need a form that sends me an email from my website but does not redirect to a different page when I click the submit button. I only want it to say "Success" or "An error occurred."
My problem is when in XAMPP I click the submit button and get the following errors: Notice: Undefined index: name in C:\xampp\htdocs\THV\process.php on line 2
Notice: Undefined index: email in C:\xampp\htdocs\THV\process.php on line 3
Notice: Undefined index: message in C:\xampp\htdocs\THV\process.php on line 4 Your message has been sent!
So even though it says message is sent I never got a email in my email.
My question is How can I create a form that sends me an email of the input of the form boxes AND get this php to not change the page but display "your message has been sent" below the submit button? Here is my code:
<?php $name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$from='From: Test';
$to='versionabstracts@gmail.com';
$subject='Test';
$body="From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
/* Anything that goes in here is only performed if the form is submitted */
}
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo'<p>Your message has been sent!</p>';
}
else {
echo'<p>Something went wrong, go back and try again!</p>';
}
}
?>
<div class="container">
<div class="row">
<div class="five columns">
<form method="post" action="process.php">
<label>Name</label>
<input name="" placeholder="Name">
<label>Email</label>
<input name="" type="email" placeholder="Email">
<label>Message</label>
<textarea name="" placeholder="Message"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</div>
</div>
</div>