8 Replies Latest reply: Mar 21, 2013 1:11 PM by tonyb1117 RSS

    why is my php form not sending to my e-mail?

    tonyb1117

      Here i have the code for my .php document and the code for my html. Why is the form not sending to my e-mail (browna.shu@gmail.com)? At one point I had the form sending to my e-mail, but the information that was filled out was not appearing. Now no email is being sent at all. I tried a contact-us.php page with the php email code in the same document and now have the information in seperate documents, but I am getting the same results every which way. I need help I have been checking this over for hours and looking up solutions online but it all is very confusing. PLEASE HELP!

       

       

      send.php

       

      <?php

       

       

      if ($_POST['parse_var'] == "contactForm") {

       

                $emailTitle = 'Scheduele In Home Consultation or General Question';

                $yourEmail = 'browna.shu@gmail.com';

       

                $firstName = $_POST['FirstName'];

                $lastName = $_POST['LastName'];

                $phoneNumber = $_POST['PhoneNumber'];

                $emailAddress = $_POST['EmailAddress'];

                $Message = $_POST['Message'];

       

                $body = <<<EOD

      <br><hr><br>

                First Name: $firstName <br />

                Last Name: $lastName <br />

                Phone Number: $phoneNumber <br />

                Email Address: $emailAddress <br />

                Message: $Message <br />

       

      EOD;

       

                $headers = "From: $emailAddress\r\n";

                $headers .= "Content-type: text/html\r\n";

                $success = mail("$yourEmail", "$emailTitle", "$body", "$headers");

       

                $sent = "Thank you! Your message has been sent.";

      }

       

       

      ?>

       

       

       

       

       

       

       

      contact-us.html

       

       

            <form action="send.php" method="post" name="contactForm" id="contactForm">

              <table width="75%" align="left" cellpadding="5" id="contactustable">

                <tr>

                  <td><label for="FirstName"></label>

                    <span id="sprytextfield1">

                    First Name<br>

                    <br>

                    <input type="text" name="FirstName" id="FirstName" value="<?php print "$firstName"; ?>">

                  <span class="textfieldRequiredMsg">Please enter your first name.</span></span></td>

                </tr>

                <tr>

                  <td> </td>

                </tr>

                <tr>

                  <td><label for="LastName"></label>

                    <span id="sprytextfield2">

                    Last Name<br>

                    <br>

                    <input type="text" name="LastName" id="LastName" value="<?php print "$lastName"; ?>">

                  <span class="textfieldRequiredMsg">Please enter your last name.</span></span></td>

                </tr>

                <tr>

                  <td> </td>

                </tr>

                <tr>

                  <td><label for="PhoneNumber"></label>

                    <span id="sprytextfield3">

                    Phone Number<br>

                    <br>

                    <input type="text" name="PhoneNumber" id="PhoneNumber" value="<?php print "$phoneNumber"; ?>">

      <span class="textfieldInvalidFormatMsg">Please enter your phone number.</span></span></td>

                </tr>

                <tr>

                  <td> </td>

                </tr>

                <tr>

                  <td><label for="EmailAddress"></label>

                    <span id="sprytextfield4">E-mail Address<br>

                    <br>

                    <input type="text" name="EmailAddress" id="EmailAddress" value="<?php print "$emailAddress"; ?>">

                  <span class="textfieldRequiredMsg">Please enter your e-mail address.</span><span class="textfieldInvalidFormatMsg">Example: myemail@email.com.</span></span></td>

                </tr>

                <tr>

                  <td> </td>

                </tr>

                <tr>

                  <td height="255"><label for="Message"></label>

                    <span id="sprytextarea1">

                    Message:<br>

                    <br>

                    <textarea name="Message" cols="85%" rows="12" id="Message"><?php print "$Message"; ?></textarea>

                  <span class="textareaRequiredMsg">A value is required.</span></span></td>

                </tr>

                <tr>

                  <td> </td>

                </tr>

                <tr>

                  <td><input type="submit" name="Reset" id="Reset" value="Reset">

                    <input type="hidden" name="parse_var" id="parse_var">             

                  <input type="submit" name="Submit" id="Submit" value="Send Message"></td>

                </tr>

                <tr>

                  <td><?php print "$sent"; ?></td>

                </tr>

              </table>

            </form>

        • 1. Re: why is my php form not sending to my e-mail?
          bregent CommunityMVP

          What is this all about?

          if ($_POST['parse_var'] == "contactForm") {

           

          You don't have a form field named 'parse_var' with a value of contactForm. What were you trying to do here?

          • 2. Re: why is my php form not sending to my e-mail?
            osgood_ CommunityMVP

            If you are seperating the form and the processing script into two individual files then you don't need:

             

            if ($_POST['parse_var'] == "contactForm") {

             

            OR

             

            the closing curly bracket after the $sent variable and before the closing ?> php tag:

             

            $sent = "Thank you! Your message has been sent.";

             

            }

             

            ?>

            • 3. Re: why is my php form not sending to my e-mail?
              tonyb1117 Community Member

              It works! Thank you very much for pointing that out "bregent" and "osgood_". I have one more small problem though, when signing out my contact form the phone number field does not accept any phone number?

               

                            <input type="text" name="PhoneNumber" id="PhoneNumber" value="<?php print "$phoneNumber"; ?>">

              <span class="textfieldInvalidFormatMsg">Please enter your phone number.</span></span></td>

               

              Any solutions?

              • 4. Re: why is my php form not sending to my e-mail?
                osgood_ CommunityMVP

                tonyb1117 wrote:

                 

                It works! Thank you very much for pointing that out "bregent" and "osgood_". I have one more small problem though, when signing out my contact form the phone number field does not accept any phone number?

                 

                              <input type="text" name="PhoneNumber" id="PhoneNumber" value="<?php print "$phoneNumber"; ?>">

                <span class="textfieldInvalidFormatMsg">Please enter your phone number.</span></span></td>

                 

                Any solutions?

                 

                 

                 

                I don't know anything about Spry validation of form fields but I think it requires you to set the type of validation, i.e., text, email, number.

                 

                Have you looked in that direction.

                 

                I presume what youre saying is when you hit send you get a red message saying phone number is not valid or something along those lines?

                • 5. Re: why is my php form not sending to my e-mail?
                  MurraySummers CommunityMVP

                  I don't see any Spry tagging of that field, though, so like you I am curious what is meant by "the phone number field does not accept any phone number?".

                  • 6. Re: why is my php form not sending to my e-mail?
                    osgood_ CommunityMVP

                    The OP has only posted a snip of the form field:

                     

                    <td><label for="PhoneNumber"></label>

                                  <span id="sprytextfield3">

                                  Phone Number<br>

                                  <br>

                                  <input type="text" name="PhoneNumber" id="PhoneNumber" value="<?php print "$phoneNumber"; ?>">

                    <span class="textfieldInvalidFormatMsg">Please enter your phone number.</span></span></td>

                    • 8. Re: why is my php form not sending to my e-mail?
                      tonyb1117 Community Member

                      Yes I have looked in that direction, I changed the type= from 'text' to 'number' and found somewhere online saying to try 'tel' and for each type a red message pops up saying "Please enter your phone number". I have tried typing the phone number like, "555-555-5555" "5555555555" "(555)555-5555" "1-555-555-5555" and "1(555)555-5555" but nothing is working. Im not sure what to do to fix this and I can't find much on the phone spry validation of the form.