Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Contact Form

    Hello,

    I am having some problems with PHP code to send my form submissions to an email address: I have the following code at present,

    PHP Code:
    mail($email'New Contact Us Form'$values['text'], "From: \"{$values['name']}\" <{$values['email']}>"); 
    This produces an email but no data is shown on it. Can anyone help with how I need to adjust the code so that all fields from the contact form display on the resulting email.

    The values for the fields I have in the form are: name, phone, email, comments.

    Also, after the user submits my form, if there are uncompleted fields, the page is re-loaded with the form error messages. At the moment, the page re-loads to the top, however I would like it to re-load at the same position that the contact form sits. If it's possible, what code would I need to use?

    Many Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What is in $values['text']? I'd bet it's blank. Find out by inserting <icode>echo $values['text'];</icode> before the mail() call.

    You can't really control page position like you want. You could use in-page anchor tags (google it), but that will only approximate what position the page was in when the form was submitted. (which may be good enough for you)

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply. I have used a page anchor and also added it to the form action code which seems to work.

    I'm having some problems with the redirect to a confirmation page. I have tried using the header code below but this doesn't redirect?

    PHP Code:
    <?php

       header
    'Location: http://www.yoursite.com/new_page.html' ) ;

    ?>
    I've also used the meta code below and this works however there is a slight delay before the page redirects even though content is set at 0? Any ideas why this is?

    PHP Code:
    $url 'confirmation.html';
        echo 
    '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    header() works fine, I use it all the time, but you may have already produced output before calling header(), which produces errors/warnings, which you may not be seeing because you may have error reporting turned off. Make sure error reporting is turned on while you are writing code.

    The <meta refresh> tag has a delay because the page has to fully load to the browser before it fires off. header() doesn't load anything to the browser.

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your help, I've managed to get the header code working now


  •  

    Posting Permissions

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