ColGam Posted January 30, 2017 Share Posted January 30, 2017 Hi. I am relatively new to using PHP and am working on building a contact form. It's pretty much good to go and it sends to my email, however, I am having the issue where it just sends this information to my email and not what the user put in, just leaving the message blank. Name: Email: Phone: Message: I'm not exactly sure what I am doing incorrectly. Also is there way to improve my code to make sure it gets in my inbox and not my spam? I've included the PHP and the HTML regarding the form. Here's the PHP. <?php $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $formcontent=" From: $name \n Email: $email \n Phone: $phone \n Message: $message"; $recipient = "contact@immersivewebdesign.com"; $subject = "Contact Form"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='http://immersivewebdesign.com/' style='text-decoration:none;color:#ff0099;'> Return Home</a>"; ?> Here's the HTML form. <div class="container"> <div class="col-lg-offset-4 col-lg-4" id="panel"> <h2>Get In Touch</h2> <form action="mail.php" method="post"> <div class="group"> <input type="text" name="name" required> <span class="highlight"></span> <span class="bar"></span> <label>Name</label> </div> <div class="group"> <input type="email" email="email" required> <span class="highlight"></span> <span class="bar"></span> <label>Email</label> </div> <div class="group"> <input type="tel" phone="phone" required> <span class="highlight"></span> <span class="bar"></span> <label>Phone</label> </div> <div class="group"> <input type="text" message="message" required> <span class="highlight"></span> <span class="bar"></span> <label>Message</label> </div> <div class="group"> <center> <button type="submit" class="btn btn-warning">Send <span class="glyphicon glyphicon-send"></span></button></center> </div> </form> </div> </div> Thank you for your help. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 31, 2017 Share Posted January 31, 2017 That PHP code is open to attacks because you're not validating anything, but I would start by enabling all error messages. That PHP code is going to send an email regardless of whether the form was submitted, so maybe that's the issue. Add this to the top of your code: ini_set('display_errors', 1); error_reporting(E_ALL); Link to comment Share on other sites More sharing options...
ColGam Posted January 31, 2017 Author Share Posted January 31, 2017 Thank you! So I gave that a try and the form comes back with just the name input filled in and the rest blank. I also get these errors when I submit the form on the site.Notice: Undefined index: email in /home/jdtvhiyt/public_html/mail.php on line 7Notice: Undefined index: phone in /home/jdtvhiyt/public_html/mail.php on line 8Notice: Undefined index: message in /home/jdtvhiyt/public_html/mail.php on line 9 Do you have any thoughts on this? Link to comment Share on other sites More sharing options...
dsonesuk Posted January 31, 2017 Share Posted January 31, 2017 All inputs require a name attribute with name value, that is what $_POST, $_GET look for to retrieve the values from post, get array when the form is submitted. Link to comment Share on other sites More sharing options...
thescientist Posted February 10, 2017 Share Posted February 10, 2017 Check out the w3schools tutorials http://www.w3schools.com/php/php_forms.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now