Results 1 to 15 of 15

Thread: Simple PHP email form won't email results

  1. #1
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default Simple PHP email form won't email results

    I have made a very simple email form, and I'm having trouble with it emailing me the results. The url for the test form that I made is at http://universalcarpet.org/form.html

    Can someone look at these codes and see what I'm doing wrong please?

    here is the PHP code titled inquire.php

    <?php

    /* Subject and Email Variables */

    $emailsubject = 'Quote Form Inquire';
    $webMaster = 'john@universalcarpet.org';

    /* Gathering Data*/

    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $phoneField = $_POST['phone'];
    $zipField = $_POST['zip'];

    $body = <<<EOD
    <br><hr><br>
    Name: $name <br>
    Email: $email <br>
    Phone: $phone <br>
    Zip Code: $zip <br>
    EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($webMaster, $emailsubject, $body, $headers);


    /* Results rendered as HTML*/

    $theResults = <<<EOD

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <h2 align="center">Thank you for your request, we will contact you very soon! </h2>
    </body>
    </html>

    EOD;
    echo "$theResults";


    ?>

    Here is the html code for the form

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <table width="225" border="0" cellspacing="5" cellpadding="5">
    <tr>
    <td bgcolor="#336699"><form action="inquire.php" method="post" name="form">
    <p>Name<br />
    <input name="name" type="text" id="name" />
    </p>
    <p>Email<br />
    <input name="email" type="text" id="email" />
    </p>
    <p>Phone<br />
    <input name="phone" type="text" id="phone" />
    </p>
    <p>Zip Code<br />
    <input name="zip" type="text" id="zip" />
    </p>
    <p>
    <input name="Submit" type="submit" id="submit" value="Submit" />
    <input name="Submit" type="reset" id="Submit" value="Reset" />
    </p>
    </form></td>
    </tr>
    </table>
    </body>
    </html>

    Thank you in advance for any help you can give me!

  2. #2
    Join Date
    Jan 2009
    Location
    Sylvarant
    Posts
    170

    Default

    What is wrong specifically?
    Nick
    "Beware of bugs in the above code; I have only proved it correct, not tried it."
    - Donald E. Knuth.

  3. #3
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default

    Quote Originally Posted by sikuneh View Post
    What is wrong specifically?
    I never receive an email. It won't send the form, however it does go to the thank you page. I've tried three different emails as well, and it still won't send it. I'm pretty sure it must be in the php code, but I can't figure it out.

  4. #4
    Join Date
    Jan 2009
    Location
    Sylvarant
    Posts
    170

    Default

    Is $success returning true or false. Try a try/catch statement. Something like:
    PHP Code:
    <?php
    // ..
    try
    {
        
    $success mail($webMaster$emailsubject$body$headers);
        echo 
    $success;
    }
    catch (
    Exception $e)
        echo 
    "There was a problem: " $e->getMessage();
    Nick
    "Beware of bugs in the above code; I have only proved it correct, not tried it."
    - Donald E. Knuth.

  5. #5
    Join Date
    Sep 2012
    Posts
    301

    Default

    Could you not use a free email form for this? I know what a pain it can be but some of the free forms like Jotform and Kontact are pretty customisable. I have signed up for new accounts for each new website using the forms. You can technically sign up for several accounts and use several identical forms on different pages of the site - this gets around the issue of reaching the quota for receiving messages free. Otherwise you have to pay to receive the emails.

  6. #6
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default

    Quote Originally Posted by sikuneh View Post
    Is $success returning true or false. Try a try/catch statement. Something like:
    PHP Code:
    <?php
    // ..
    try
    {
        
    $success mail($webMaster$emailsubject$body$headers);
        echo 
    $success;
    }
    catch (
    Exception $e)
        echo 
    "There was a problem: " $e->getMessage();
    Where do I put this code? I tried to put it at top of the php page, and by the $success = mail($webMaster, $emailsubject, $body, $headers); area, but when I published it, it said internal error 500. Do I make this a page by itself and attach that page to me html form? I'm new at this stuff, sorry, but I have limited knowledge.. lol

    Thanks,
    John

  7. #7
    Join Date
    Jan 2009
    Location
    Sylvarant
    Posts
    170

    Default

    You put the try right above the $success variable, then replace $success with what's in the try.
    Nick
    "Beware of bugs in the above code; I have only proved it correct, not tried it."
    - Donald E. Knuth.

  8. #8
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default

    Darren,
    Ya I've done that a bunch of times, but I'd really like to be able to do it myself... but I appreciate your help ;-)

  9. #9
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default

    Quote Originally Posted by sikuneh View Post
    You put the try right above the $success variable, then replace $success with what's in the try.
    Here is where I put the code.. I have it in bold... I still got the same error on this.

    <?php


    /* Subject and Email Variables */

    $emailsubject = 'Quote Form Inquire';
    $webMaster = 'john@universalcarpet.org';

    /* Gathering Data*/

    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $phoneField = $_POST['phone'];
    $zipField = $_POST['zip'];

    $body = <<<EOD
    <br><hr><br>
    Name: $name <br>
    Email: $email <br>
    Phone: $phone <br>
    Zip Code: $zip <br>
    EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    try
    {
    $success = mail($webMaster, $emailsubject, $body, $headers);
    echo $success;
    }
    catch (Exception $e)
    echo "There was a problem: " . $e->getMessage();



    /* Results rendered as HTML*/

    $theResults = <<<EOD

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <h2 align="center">Thank you for your request, we will contact you very soon! </h2>
    </body>
    </html>

    EOD;
    echo "$theResults";


    ?>

  10. #10
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default

    I had to change my php to a older version on my host account.. it now gave me a code on where I put the variable above.. here is the message:
    Parse error: syntax error, unexpected '{' in /home/www/universalcarpet.org/inquire.php on line 27

    on line 27 it is this { right after the word try.

  11. #11
    Join Date
    Jan 2009
    Location
    Sylvarant
    Posts
    170

    Default

    I wrote in a try without braces.
    PHP Code:
    try
    {
        
    // $success goes here
    }
    catch (
    Exception $e)
    {
        
    // Catch goes here

    Nick
    "Beware of bugs in the above code; I have only proved it correct, not tried it."
    - Donald E. Knuth.

  12. #12
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default

    I got the same message.. I'm sure I'm doing something wrong.. I don't know anything about php, so unless I can copy and paste in a code, I'm lost! lol..

    this is what I typed in..
    try
    {
    $success = mail($webMaster, $emailsubject, $body, $headers);
    echo $success;
    }
    catch (Exception $e)
    {
    echo "There was a problem: " . $e->getMessage();
    }

    it's still telling me that the { is my problem.. So I'm lost. But I thank you for your time sir.. You have to understand I'm like a total beginner at this so its like your talking to a 3 yr old.. lol

    Thanks again

  13. #13
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

    Default

    I found out that it is working fine in Mozilla Firefox, but it's not sending the email in Chrome. So it must not be the php, but my browser preferences i guess.. thanks guys!

  14. #14
    Join Date
    Aug 2010
    Location
    Pattaya, Thailand
    Posts
    1,822

    Default

    I don't see how it could be working fine when obviously it is not going to collect anything:
    /* Gathering Data*/

    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $phoneField = $_POST['phone'];
    $zipField = $_POST['zip'];

    $body = <<<EOD
    <br><hr><br>
    Name: $name <br>
    Email: $email <br>
    Phone: $phone <br>
    Zip Code: $zip <br>
    EOD;
    See for instance $name and $nameField.. They should be the same.

    As for actually sending the email, some webhosting providers change the order of arguments of the mail function in an attempt to prevent automated hackers from easily using their servers to send spam via pre-made scripts. But in that case they make it clear in their FAQ for their customers.

  15. #15
    Join Date
    Jan 2009
    Location
    St. Louis, MO
    Posts
    83

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •