Jump to content
ColGam

PHP not sending information from contact form

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites

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 7

Notice: Undefined index: phone in /home/jdtvhiyt/public_html/mail.php on line 8

Notice: Undefined index: message in /home/jdtvhiyt/public_html/mail.php on line 9

 

Do you have any thoughts on this?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...