treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] CONTACT FORM not working ... please help!!

  • Guys, I need help!! I'm banging my head on the wall trying to resolve!

    When I click 'SEND' I'm getting an error message on line 33. I can't figure out what's going on!

    Please, your help is GREATLY appreciated.

  • @hendrix940 Post your code but remove any sensitive information, first.

  • @chrisburton, I'm new to the forums, can you please advise me the best way to do this? Thanks!!

  •     <?php
                    $subject = "Comment/Question from the site.";
            $message = "$question";
            $mail_from = "$email";
    
            $header = "from: $name <$mail_from>";
    
            $to = "email@gmail.com"
    
            $send_contact = mail($to,$subject,$message,$header);
    
            if($send_contact){
              echo "<p>We've received your email.  We will email you back shortly.</p>";
            }
            else {
              echo "Error.  Please go back and try again.";
            }
                  ?>
    
  • Okay, that's my PHP

  •    <div class="content-half">
                      <form action="" method="post" id="contact-form">
                          <div class="contact-form-input contact-input-wrapper">
                              <label class="contact-label">Name:</label>
                              <input type="text" name="name" class="required" />
                          </div>
                          <div class="contact-form-input contact-input-wrapper">
                              <label class="contact-label">E-mail:</label>
                              <input type="text" name="email" class="required email" />
                          </div>
                          <div class="contact-form-textarea contact-input-wrapper">
                              <label class="contact-label">Letter:</label>
                              <textarea name="question" rows="" cols="" class="required"></textarea>
                          </div>
                          <input type="submit" name="Submit" value="Send" class="button send-button">
                          <div class="clear"></div>
                      </form>
    
  • @hendrix940 I only want what's on line 33 for now. So just create an empty space/line, hit the spacebar 4x and paste.

  • that's the html calling on the .php. Did I include everything?

  •           $send_contact = mail($to,$subject,$message,$header);
    
  • Thank you sir. Above is line 33.

  • @hendrix940 What's this about?

      $to = "email@gmail.com"
    

    Shouldn't it be:

      $to = "email@gmail.com";
    
  • that very well could be it @chrisburton ... testing now.

  • @chrisburton, now it is sending (THANK YOU), HOWEVER, it's not sending any of the information from the text fields. Just an email shows up with no information in the inbox.

  • Next time, include the actual error message. PHP does reasonably well at telling you what the problem is - you don't have to guess.

  • ...HOWEVER, it's not sending any of the information from the text fields. Just an email shows up with no information in the inbox.

          $message = "$question";
          $mail_from = "$email";
    
          $header = "from: $name <$mail_from>";
    

    where do you define the variables $question, $email, $name, $mail_from, etc.? Are you sure they contain the values you expect?

  • Okay thanks @traq, currently I am not receiving an error message, after the above fix that @chrisburton recommended. Emails are being sent, HOWEVER they are just blank emails, no information from the text fields is being sent over.

  • @traq, sir, I do not know the answer. I had another gentleman write the PHP code for me and I only know what I sent over. Please your advise is greatly appreciated.

  • Okay, I'm figuring this out. I just have one field now that is not sending over. If I'm unable to figure this out by the evening, I'll post again. @chrisburton, thank you again for your help. @traq, thank you.

  • If you need more help, you'll probably need to share the entire script with us (which is not easy to do in a css-tricks forum post). I'd suggest writing a gist on github:

    (1). copy+paste your entire script

    (2). ***** out any sensitive info (like private email addresses, usernames, passwords, database credentials, etc.)

    (3). click [Create Public Gist].

    Then, share the URL with us.

  • @hendrix940 can you paste the whole source file here, i am also confused with contact forms