PHP to email form results

Discussion in 'HTML / PHP / JavaScript / CSS' started by thpinck, Aug 2, 2012.

  1. I am new at this and am having a strange (at least to me) problem. I have a form to collect login request information on an html page, it calls a php page that captures the form information and emails it to me. I do all the input verification in the html page. I fill out the form and submit it, everything looks good. I get the success message, and in the success message I also printed out the message body content and the email address and all is correct.
    The problem is I never receive the message; I have no idea where it is going if at all. No error messages of any kind just no messages.

    My html page:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact Form</title>
    <script type="text/javascript" src="_assets/modernizr-1.7.js"></script>
    <script type="text/javascript" src="_assets/jquery-1.7.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    if (!Modernizr.input.autofocus) {
    $("input[autofocus]").focus(); // give focus to whichever element has the autofocus attribute
    } });
    </script>
    <script type="text/javascript" src="_assets/placeholder.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    if (!Modernizr.input.placeholder) { makePlaceholders(); } }); </script>
    <script type="text/javascript" src="_assets/webforms2-0.5.4/webforms2.js"></script>
    <style type="text/css"> :invalid { background-color: #ffdddd; }
    :valid { background-color: #ddffdd; }
    :required {border-color: #800000; border-width: 3px; }
    </style>
    <script type="text/javascript" src="_assets/jquery-1.7.2.js"></script>
    <script> $("document").ready(function() {$("input[required]").css("border", "3px solid #800000");});
    </script>
    </head>
    <body>
    <form name="contactform" method="post" action="emailForm.php">
    <table>
    <tr>
    <td><label for="first_name">First Name *</label></td>
    <td><input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autocomplete="on" required="required" autofocus="autofocus" ></td>
    </tr>
    <tr>
    <td><label for="last_name">Last Name *</label></td>
    <td><input type="text" name="last_name" maxlength="50" size="30" autocomplete="on" required="required" placeholder="Last Name" ></td>
    </tr>
    <tr>
    <td><label for="Company_Name">Company Name *</label></td>
    <td><input type="text" name="Company_Name" maxlength="80" size="30" autocomplete="on" required="required"placeholder="Rapid Desktop Solutions LLC"></td>
    </tr>
    <tr>
    <td> <label for="Telephone">Telephone Number *</label></td>
    <td><input type="tel" name="telephone" maxlength="16" size="16" autocomplete="on" required="required" placeholder="(999)999-9999" pattern="[\(]\d{3}[\)]\d{3}[\-]\d{4}"></td>
    </tr>
    <tr>
    <td><label for="best time">Best time to call *</label></td>
    <td><input type="text" name="best_time" maxlength="10" size="7" autocomplete="on" required="required" placeholder="0000" pattern="^[0-9]{4}$" />
    &nbsp;&nbsp;<label for"AM_PM">AM/PM</label>
    <select name="ampm" id="am_pm" required="required">
    <option value="AM">AM</option>
    <option value="PM">PM</option>
    </select>
    &nbsp;&nbsp;
    <label for="timez">Time Zone</label>&nbsp;
    <select name="timez" id="timez" required="required">
    <option value="eastern">Eastern</option>
    <option value="central">Central</option>
    <option value="moutain">Mountain</option>
    <option value="pacific">Pacific</option>
    </select></td>
    </tr>
    <tr>
    <td align="center"><label for="comments">Comments: </label></td>
    <td><textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> </td>
    </tr>
    <tr>
    <td><input type="submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    The PHP code:


    <?php
    $email_to = "[email protected]";
    $email_subject = "Portal access request";
    $first_name = $_POST['first_name']; # required
    $last_name = $_POST['last_name']; # required
    $Company_Name = $_POST['Company_Name']; # required
    $telephone = $_POST['telephone']; # required
    $best_time = $_POST['best_time']; # required
    $am_pm = $_POST['ampm']; # required
    $timez = $_POST['timez']; # required
    $comments = $_POST['comments']; # required
    $email_message = $first_name .
    $last_name .
    $Company_Name .
    $telephone .
    $best_time .
    $am_pm .
    $timez .
    $comments;
    # create email headers
    $headers = 'From: '.
    $email_from."\r\n".
    'Reply-To: '.
    $email_from."\r\n" .
    'X-Mailer: PHP/' .
    phpversion();

    @mail($email_to, $email_subject, $email_message, $headers);

    (I have tried this line with and without the leading @ symbol, same results)

    echo "Your request for access to our Portal page has been
    sent. <br/>";
    echo "You will be contacted within 48hours.<br/>";
    echo " Thank you for your interest, we look forward to serving you.<br/>";

    echo " set to: " . $email_to;
    ?>
     
  2. mjp

    mjp

    mail() isn't going to work because that function sends without SMTP authentication and we don't allow that.

    You can pass SMTP authentication through a php mailing script, but I don't think anyone has posted a working example here yet. You might want to try a Google search for "php mail() smtp authentication."
     
  3. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

  4. Thank you all for the replays. I look at the article and will try it when I get back to my computer. One question the first line of code is require_once "Mail.php";*
    Is the mail.php something that resides on the server? As you can tell I am very new to php.
     
  5. mjp

    mjp

  6. problem was mixed, sorry for teh late reply
     
  7. I am having the same problem with the mail.php file. New to php so not sure if i'm missing something. When I try to test it, I get the message:

    'Warning: require_once(Mail.php): failed to open stream: No such file or directory .... '

    (this is using the code from the knowledge base artice)

    I am only trying to get a simple form set up and can't seem to get round this!
     
  8. You may want to check which PHP engine you are using. If you connect to the server using IIS Manager and go to Handler Mappings. You should see two PHP engines. One is Microsoft's version of PHP wich is PHP_FastCGI and the other is just PHP. The one that is just PHP is the original PHP engine from PHP themselves. You can move one up or down and force your application to use that PHP engine.
     

Share This Page