php mail form blues

Discussion in 'Web Design & Coding' started by dubstar, Mar 28, 2006.

  1. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    so i've been checking out tutorials and i cant figure out whats wrong..

    The Form
    <form method="post" action="contact.php">
    Contact **********
    <br />
    <input type="text" name="name" value="name" size="33" />
    <br />
    <input type="text" name="email" value="email" size="33" />
    <br />
    Mailing list subscription?
    <input name="mailinglist" type="checkbox" value="mailinglist" checked />
    <br />
    <textarea name="message" rows="10" cols="30">message</textarea>
    <br />
    <input type="submit" value="submit" />
    </form>


    The PHP Page > Error is on line 27.. "Parse error: parse error, unexpected $ in...." It's where </HTML> is at. I dont understand what i didnt close.
    Code:
    <!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>
    <title>Cellar Door - Long Beach</title>
    </head>
    
    <body>
    <?
    $name = $_REQUEST['name'] ;
    $email = $_REQUEST['email'] ;
    $mailinglist = $_REQUEST['mailinglist'] ;
    $message = $_REQUEST['message'] ;
    
    if (!isset($_REQUEST['email'])) {
        header( "Location: /not_sent.html" );
    }
    elseif (empty($email) || empty($message) ||empty($name)) {
        header( "Location: /not_sent.html" );
    }
    else {
        mail( "***@***.com", "***** Website Form",
        "$message\n\nDid they subcribe to the mailing list?? $mailinglist\n\n",
        "From: $name <$email>" );
        header( "Location: /sent.html" );
        ?>
        </body>
        </html>
     
  2. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    you've not closed the } on the last else
     
  3. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    heh thats probably the hardest error to spot :p
     
    dubstar likes this.
  4. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    thanks so much.

    but now its

    "Cannot modify header information - headers already sent by contact.php:8 on line 25"

    grrr.. i tried blocking out the first if/else and it still says this.

    Code:
    <?
    $name = $_REQUEST['name'] ;
    $email = $_REQUEST['email'] ;
    $mailinglist = $_REQUEST['mailinglist'] ;
    $message = $_REQUEST['message'] ;
    
    //if (!isset($_REQUEST['email'])) {
    //    header( "Location: /not_sent.html" );
    //}
    //else
    if (empty($email) || empty($message) ||empty($name)) {
        header( "Location: /not_sent.html" );
    }
    else {
        mail( "**@**.com", "** Website Form",
        "$message\n\nDid they subcribe to the mailing list?? $mailinglist\n\n",
        "From: $name <$email>" );
        header( "Location: h/sent.html" );
    }
        ?>
     
  5. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    becuase it prcesses the page as it reads it, thus the html already sets the headers. put the html header code after the php code

    or don't put any html in it at all, since you never see the page

    or at the top of the page
    put
    PHP:
    <?php
    ob_start
    'ob_gzhandler' );
    ?>
    which causes the page to be processed first and then displayed (and can speed up pages)
     
    dubstar likes this.
  6. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    ohhh.. i overlooked that for sure.

    what'd your paypal address. you just saved me endless man-hours!
     
  7. Admiral Michael

    Admiral Michael Michaelsoft Systems CEO Folding Team

    I use an ASP sendmail script to connect to my mail server and I have the form page and the sendmail script in another file. Submit form to sendmail.asp and then redirect back to contact.asp.

    I like to separate it this way.
     
    dubstar likes this.
  8. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    grrr. it works but it isnt sending the mail.

    i hate to do this but here is the form and revised (thank you) php.

    Code:
    <form method="post" action="contact.php">
    Contact Cellar Door
    <br />
    <input type="text" name="name" value="name" size="33" />
    <br />
    <input type="text" name="email" value="email" size="33" />
    <br />
    Mailing list subscription?
    <input name="mailinglist" type="checkbox" value="mailinglist" checked />
    <br />
    <textarea name="message" rows="10" cols="30">message</textarea>
    <br />
    <input type="submit" value="submit" />
    </form>


    Code:
    <?
    $name = $_REQUEST['name'] ;
    $email = $_REQUEST['email'] ;
    $mailinglist = $_REQUEST['mailinglist'] ;
    $message = $_REQUEST['message'] ;
    
    if (empty($email) || empty($message) ||empty($name)) {
        header( "Location: not_sent.html" );
    }
    else {
        mail( "theEmailAddress@hotmail.com", "Cellar Door Website Form",
        "$message\n\nDid they subcribe to the mailing list?? $mailinglist\n\n",
        "From: $name <$email>" );
        header( "Location: sent.html" );
    }
        ?>
    
    (theEmailAddress@hotmail.com was added for privacy)
     
    Last edited: Mar 30, 2006
  9. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    does it just fail sending the mail? i.e. is there an error returned from the mail command or just not delivering mail?. It looks ok technically, make sure the sever sendmail is configured and turned on
     
  10. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    no errors. it goes to the "sent.html" as if everything was properly coded.

    maybe my host turned it off? i've tried contacting them but they havent replied in over 8 months. -- hosting is only $12 a year. :/

    warning: do not use webcountry.net!


    thanks for your help Khayman.
     
  11. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    it will go to sent.html if it goes or not

    mail returns true or false depending if it work, try capturing that and checking it to see if it makes a difference. try different email addresses, make sure it spelt right ;)
     
  12. Admiral Michael

    Admiral Michael Michaelsoft Systems CEO Folding Team

    Does your host even support the mail script?
     
  13. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    i pay for PHP, so.. doesnt that mean he supports it? :/
     
  14. Admiral Michael

    Admiral Michael Michaelsoft Systems CEO Folding Team

    Im not sure, you MAY need some sort of mail server support.
     
  15. loanskey

    loanskey OSNN One Post Wonder

    Messages:
    1
    what editor you are using for your work.
    I mean what PHP editor

    you have having very basic problems those can be removed by the good editor