#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    24
    Rep Power
    0

    QUICK & EASY mail form question


    Why won't the following submit? It's a simple mail form, I've uploaded it and tried testing on the server but it's not posting through. Any help appreciated.

    PHP Code:
    <?php
    if ($_POST["email"]<>'') {
            
    $ToEmail 'bob.berry@volstate.edu';
            
    $EmailSubject 'Library Survey Form';
            
    $mailheader "From: ".$_POST["UserName"]."\r\n";
            
    $mailheader .= "Reply-To: ".$_POST["UserEmail"]."\r\n";
            
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
            
    $MESSAGE_BODY "Name: ".$_POST["Name"]."";
            
    $MESSAGE_BODY .= "Select1: ".$_POST["Select1"]."";
            
    $MESSAGE_BODY .= "Select2: ".$_POST["Select2"]."";
            
    $MESSAGE_BODY .= "Comments: ".$_POST["Comments"]."";
            
    $MESSAGE_BODY .= "UserTel: ".$_POST["UserTel"]."";
            
    $MESSAGE_BODY .= "ContactRequested: ".nl2br($_POST["ContactRequested"])."";
            
    mail($ToEmail$EmailSubject$MESSAGE_BODY$mailheader) or die ("Failure");
    ?>
            Your message was sent
        <?php
            
    } else {
        
    ?>
            
          <form action="survey.php" method="POST">
            <p><strong>Please enter the name of the trainer:&nbsp;
            </strong><input name="Name" type="text" style="width: 296px" value=" "></p>
            <p><strong>Was the trainer easy to understand?&nbsp; </strong>
            <select name="Select1" style="width: 58px">
            <option value="No">No</option>
            <option selected="" value="Yes">Yes</option>
            </select></p>
            <p><strong>Was the trainer courteous?&nbsp; </strong>
            <select name="Select2" style="width: 58px">
            <option value="No">No</option>
            <option selected="" value="Yes">Yes</option>
            </select></p>
            <p><strong>Enter your comments in the space provided below:</strong></p>
            <dl>
              <dd><textarea name="Comments" rows="5" cols="42"></textarea></dd>
            </dl>
            <p><strong>If you would like more information, please tell us how to get in touch with you:</strong></p>
            <dl>
              <dd>
                <table>
                  <tr>
                    <td>Name
                      <td><input type="text" size="35" maxlength="256" name="Username">
                      </tr>
                      <tr>
                        <td>E-mail
                          <td><input type="text" size="35" maxlength="256" name="UserEmail">
                          </tr>
                          <tr>
                            <td>Tel
                              <td><input type="text" size="35" maxlength="256" name="UserTel">
                              </tr>
                                </table>
                              </dd>
                            </dl>
                            <dl>
                              <dd><input type="checkbox" name="ContactRequested" value="ContactRequested">
          Please contact me as soon as possible regarding this matter.</dd>
                            </dl>
                            <p><input type="submit" name="Submit" value="Submit Comments"> <input type="reset" value="Clear Form"></p>
            </form>
            <?php
            
    };
            
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    This is not an uncommon problem. Generally it is because a mail server is not installed (postfix on Linux or something like hMailServer for Windows) or installed but not properly configured. The place to start are the mail logs to see what is happening. However, more commonly you probably don't have any mail server installed. In that case you want to use PHPMailer which allows for an external mail server.
    Last edited by gw1500se; April 3rd, 2013 at 12:09 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    721
    Rep Power
    7
    email is not an item on your form. Does UserEmail work out? And you would also want to add an isset() to your condition.

    Edit: Also note that your form has an input with the name Username, while your PHP action references UserName.
    Last edited by Triple_Nothing; April 3rd, 2013 at 02:23 PM.
  6. #4
  7. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,555
    Rep Power
    2338
    You are looking for a POST variable name to be set and not empty. Firstly you're not doing this correctly, you should be using

    php Code:
    if (isset($_POST['email']) && !empty($_POST['email'])) {


    Secondly, in order for that to be true your HTML form must have an input element with the name 'email' which is set and posted to the page. Do you have one with that name?

    Comments on this post

    • bradmartin0924 agrees
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    24
    Rep Power
    0


    Thanks!!!

    I added the bit you gave me, it's now sending out but I'll be honest. I'm not the most proficient with PHP and I want to format the email, maybe add line breaks to the sections. It all comes back jumbled together now and is almost unreadable.

    When I go to the inbox, (Unknown Sender) is who it's from. How or can I format that to be the user-email that is inserted into the form, or just a general FORM TITLE?

    Here's what I have now..

    PHP Code:
    <?php
    if (isset($_POST["UserEmail"]) && !empty($_POST['UserEmail'])) {
            
    $ToEmail 'brad@nashvillenerds.com';
            
    $EmailSubject 'Library Survey Form';
            
    $mailheader "From: ".$_POST["UserName"]."\r\n";
            
    $mailheader .= "Reply-To: ".$_POST["UserEmail"]."\r\n";
            
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
            
    $MESSAGE_BODY "Name: ".$_POST["Name"]."";
            
    $MESSAGE_BODY .= "EasyToUnderstand: ".$_POST["EasyToUnderstand"]."";
            
    $MESSAGE_BODY .= "Courteous: ".$_POST["Courteous"]."";
            
    $MESSAGE_BODY .= "Comments: ".$_POST["Comments"]."";
            
    $MESSAGE_BODY .= "UserTel: ".$_POST["UserTel"]."";
            
    $MESSAGE_BODY .= "ContactRequested: ".nl2br($_POST["ContactRequested"])."";
            
    mail($ToEmail$EmailSubject$MESSAGE_BODY$mailheader) or die ("Failure");
    ?>
            Your message was sent
        <?php
            
    } else {
        
    ?>
            
          <form action="survey.php" method="POST">
            <p><strong>Please enter the name of the trainer:&nbsp;
            </strong><input name="Name" type="text" style="width: 296px" value=" "></p>
            <p><strong>Was the trainer easy to understand?&nbsp; </strong>
            <select name="EasyToUnderstand" style="width: 58px">
            <option value="No">No</option>
            <option selected="" value="Yes">Yes</option>
            </select></p>
            <p><strong>Was the trainer courteous?&nbsp; </strong>
            <select name="Courteous" style="width: 58px">
            <option value="No">No</option>
            <option selected="" value="Yes">Yes</option>
            </select></p>
            <p><strong>Enter your comments in the space provided below:</strong></p>
            <dl>
              <dd><textarea name="Comments" rows="5" cols="42"></textarea></dd>
            </dl>
            <p><strong>If you would like more information, please tell us how to get in touch with you:</strong></p>
            <dl>
              <dd>
                <table>
                  <tr>
                    <td>Name
                      <td><input type="text" size="35" maxlength="256" name="Username">
                      </tr>
                      <tr>
                        <td>E-mail
                          <td><input type="text" size="35" maxlength="256" name="UserEmail">
                          </tr>
                          <tr>
                            <td>Tel
                              <td><input type="text" size="35" maxlength="256" name="UserTel">
                              </tr>
                                </table>
                              </dd>
                            </dl>
                            <dl>
                              <dd><input type="checkbox" name="ContactRequested" value="ContactRequested">
          Please contact me as soon as possible regarding this matter.</dd>
                            </dl>
                            <p><input type="submit" name="Submit" value="Submit Comments"> <input type="reset" value="Clear Form"></p>
            </form>
            <?php
            
    };
            
    ?>
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    Use PHPMailer. It makes formatting mail much easier, especially if you want to create multi-part mail for attachments and formatting HTML mail.

    Comments on this post

    • ptr2void agrees : Or SwiftMailer
    • DonR agrees
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo