php form

Discussion in 'Web Design and Development' started by John J Rambo, Apr 6, 2011.

  1. John J Rambo, Apr 6, 2011
    Last edited by a moderator: Apr 6, 2011

    John J Rambo macrumors member

    Joined:
    Mar 10, 2010
    Location:
    Belfast
    #1
    Hi guys,

    Im completely new to php and I'm trying link a php script to this form I have:

    PHP:
    <form action="contactformprocess.php" method="post">
            <
    fieldset>
                <
    label for="name">Name:</label>
                <
    input type="text" name="name" placeholder="Enter your full name" />

                <
    label for="email">Email:</label>
                <
    input type="email" name="email" placeholder="Enter your email address" />

                <
    label for="message">Message:</label>
                <
    textarea name="message" placeholder="What's on your mind?"></textarea>

                <
    input type="submit" value="Send message"  name="submit"/>

            </
    fieldset>
        </
    form>
    I cant see anything wrong with this form and i have linked a php mailer script to it but I'm not receiving the email...

    I'm testing it live by the way.

    thank in advance...
     
  2. CANEHDN macrumors 6502a

    CANEHDN

    Joined:
    Dec 12, 2005
    Location:
    Eagle Mountain, UT
    #2
    Can you post the PHP? The form looks okay. The PHP would help us know what's going on.
     
  3. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #3
    Aye we'll need to see at least the PHP script, the HTML you posted seems fine.
     
  4. harpster, Apr 6, 2011
    Last edited: Apr 6, 2011

    harpster macrumors regular

    Joined:
    Jan 26, 2010
    #4
    It's probably your email script...

    When you have a php form using POST variables like you do (method="post") and your not sure about the form part all you need to do is to put this test code in the page your submitting to in this case contactformprocess.php.

    PHP:
    <pre>
    <?php
    print_r
    ($_POST);
    ?> 
    </pre>

    <?php exit; ?>
    This will print out the POST array showing you all the values that were submitted. That way you know that the form submission is good if you get the expected results and you can then debug the submit to script.

    Usually I put in a exit or die statement after the closing </pre> tag to stop the script execution so I can easily see the POST array contents. The <pre> tags aren't needed but they format the array so it's easy to read.
     
  5. John J Rambo, Apr 7, 2011
    Last edited by a moderator: Apr 7, 2011

    John J Rambo thread starter macrumors member

    Joined:
    Mar 10, 2010
    Location:
    Belfast
    #5
    Hi, thanks for the responses guys. Below is my php script:

    PHP:
    <?php

    /* subject and eamil variables */


        
    $emailSubject 'hello!';
        
    $webMaster 'info@avenue19ni.com';
        

    /* Gathering Data Variables */

        
    $name $_POST['name'];
        
    $email $_POST['email'];
        
    $message $_POST['message'];
        
        
    $body = <<<EOD
    <br><hr><br>
    Name: 
    $name <br>
    Email: 
    $email <br>
    Message: 
    $message <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>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/styles.css" rel="stylesheet" type="text/css" media="screen" /> 
    <title>Contact Form Complete</title>
    </head>

    <body>


    </body>

    </html>
    EOD;
    echo 
    "$theResults";

    ?>
    thanks again, this is driving me crazy...
     
  6. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #6
    I only had a few minutes this morning to look at this but I believe the main problem is your not calling the "mail" command. You have this line but it's not doing anything as it's just a variable...

    PHP:
    $success mail($webMaster$emailSubject$body$headers);
    If you just use this it should work...

    PHP:
    mail($webMaster$emailSubject$body$headers);
    You may have other things to work out but this should send the email massage and you should be able to retrieve it at info@avenue19ni.com.
     
  7. John J Rambo thread starter macrumors member

    Joined:
    Mar 10, 2010
    Location:
    Belfast
    #7
    Hi thanks for looking at this, I tried what you said but Im still not able to receive the email, could there be a server setting or email setting that I need to enable?

    thanks
     
  8. Shannighan macrumors 6502a

    Shannighan

    Joined:
    Jul 26, 2007
    Location:
    Buffalo, NY
    #8
    you should check out phpmailer. I use it if I need to have an email form and it works really well.
     
  9. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #9
    Worked for me, sent to my gmail email address. I didn't use the form, just hard coded the variables on the email script.
     
  10. John J Rambo thread starter macrumors member

    Joined:
    Mar 10, 2010
    Location:
    Belfast
    #10
    You're a star! I just tested it with my hotmail address and it works but its not going to my other email which it needs to, any ideas?

    Its not even landing in the trash...
     
  11. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #11
    Email can be a pain.... your other account could be trashing it, who knows... try to get as simple and basic as you can with your testing. I also use phpmailer you might want to look into that. Good luck.
     
  12. bpaluzzi macrumors 6502a

    bpaluzzi

    Joined:
    Sep 2, 2010
    Location:
    London
    #12
    Just saying, this advice is incorrect. The first version was simply capturing the return value from the function. The second is discarding the return value. Both are calling the function.
     
  13. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #13
    Sorry to disagree... the script didn't work until the mail function was called directly.. maybe you should try running the code first---
     
  14. bpaluzzi macrumors 6502a

    bpaluzzi

    Joined:
    Sep 2, 2010
    Location:
    London
    #14
    There's no difference between these two bits of code in "calling it directly". Both syntaxes are directly calling the function. Do you understand how return values work?
     
  15. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #15
    All l'm saying is it didn't work.
     
  16. bpaluzzi macrumors 6502a

    bpaluzzi

    Joined:
    Sep 2, 2010
    Location:
    London
    #16
    It wasn't because of that line.
     
  17. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #17
    I was finally able to check that and your are CORRECT it wasn't that line - I found that the reason it didn't work was that I had $webmaster and $email set to the same email address and something didn't like that... case closed.
     
  18. bpaluzzi macrumors 6502a

    bpaluzzi

    Joined:
    Sep 2, 2010
    Location:
    London
    #18
    Nice! And sorry if I came across as a jerk at any point -- wasn't my intent, honest :)
     
  19. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #19
    Everything's cool :)
     
  20. CANEHDN macrumors 6502a

    CANEHDN

    Joined:
    Dec 12, 2005
    Location:
    Eagle Mountain, UT
    #20
    The mail function returns a success or denied variable. Both function calls were fine. I have had issues sending mail to gmail before. I can't remember what I did to fix it. I'm thinking it was something with the headers but it may have been with the server.
     

Share This Page