Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with contact form

Options
  • 18-09-2009 8:01am
    #1
    Closed Accounts Posts: 1,493 ✭✭✭


    Ok this is my first time trying to set up a contact form, however I keep getting this...
    Parse error: parse error in D:\hshome\#######\########.com\contactformprocess.php on line 30
    ..error message when I hit send.

    [PHP]<?php

    /* Subject and email variables */

    $emailSubject = 'PHP Scripting ';
    $webMaster = '######@#####.ie';

    /* Gathering data variables*/

    $nameField = $_POST;
    $emailField = $_POST;
    $phoneField = $_POST;
    $queriesField = $_POST;

    $body = <<<EOD
    <br><hr><br>
    Name: $name <br>
    Email: $email <br>
    Phone: $phone <br>
    Queries: $queries <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>
    <title>Untitled Document</title>
    </head>

    <body>
    sent successfully
    </body>
    </html>EOD;

    echo "$theResults";

    ?>[/PHP]
    Line 30 is
    $theResults = <<<EOD

    I've copied this pretty much word for word from a youtube tutorial & I can't see any difference. Can anybody help? It's surely something simple.


Comments

  • Registered Users Posts: 912 ✭✭✭chakotha


    I've never heard of <<<EOD in PHP.

    try
    $body = "<br><hr><br>
    Name: $name <br>
    Email: $email <br>
    Phone: $phone <br>
    Queries: $queries <br>";

    You are missing a semi-colon from the end of the mail function call.

    And I'd wrap the $theResults HTML block in quotes too and do away with the EOD.


  • Closed Accounts Posts: 1,493 ✭✭✭eddiehead


    chakotha wrote: »
    I've never heard of <<<EOD in PHP.

    try

    You are missing a semi-colon from the end of the mail function call.

    And I'd wrap the $theResults HTML block in quotes too and do away with the EOD.

    Tbh I have absolutely zero knowledge of PHP, so I can't even explain why >>>EOD is in there, like I said I just followed the instructions on the tutorial. I'll try that when I get home for lunch, thanks.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    The "<<<" (heredoc syntax) is designed to allow you to set a variable until the pattern (in this case "EOD") is encountered; it lets you avoid all of the issues related to escaping quotes.

    A rough tutorial is available here : http://www.phpf1.com/tutorial/php-heredoc-syntax.html

    The issue in this case, however, is the lack of a semi-colon on the PRECEDING line :
    $success = mail($webMaster, $emailSubject, $body, $headers)[b];[/b]
    


  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    I sometimes use an online PHP Syntax checker when I get compile time errors. (I'm too lazy to open my command line and use php.exe syntax checker).


  • Closed Accounts Posts: 1,493 ✭✭✭eddiehead


    Liam Byrne wrote: »
    The issue in this case, however, is the lack of a semi-colon on the PRECEDING line :
    $success = mail($webMaster, $emailSubject, $body, $headers)[b];[/b]
    

    Are you saying the <<<EOD thing is fine then and I just need to add a semi-colon to the line you quoted?


  • Advertisement
  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    eddiehead wrote: »
    Are you saying the <<<EOD thing is fine then and I just need to add a semi-colon to the line you quoted?
    In the online syntax checker I had to add the semicolon and move the "EOD;" text onto a new line.
    [PHP]$success = mail($webMaster, $emailSubject, $body, $headers);[/PHP]
    [PHP]</html>
    EOD;[/PHP]


  • Closed Accounts Posts: 1,493 ✭✭✭eddiehead


    Thanks for the help lads.

    It's all good now as far as the PHP is concerned, its processing the form and getting to the "sent" screen. However, the form is not making it to my inbox. What do I need to do to make the form go to my email address? Is this something I need to arrange on the server side?


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Assuming that the $webMaster variable is set to the correct address, try adding or removing either the \r or the \n within the headers; I've found this (occasionally) to be a platform-specific issue (depending on whether you're hosted on Windows or Unix, or the version of PHP).


Advertisement