php form doesn't work can anyone help ?

  1. #1
    enrique is offline Newbie

    php form doesn't work can anyone help ?

    I'm trying to use the following script to process a form (below) I've been racking my brains over this one and am at breaking point....it just doesn't seem to work can anyone help ?

    <?php
    // Get submitted data
    $name = $HTTP_POST_VARS['name'];
    $company = 'From: '.$HTTP_POST_VARS['company'];
    $phone = $HTTP_POST_VARS['phone'];
    $message = $HTTP_POST_VARS['message'];

    // Put data into readable format
    $to = 'enrique@hotmail.co.uk';
    $body = 'Name: '.$name.'\n'
    .'Company: '.$company.'\n'
    .'email: '.$email.'\n'
    .'Message: \n \n'.$message;

    // Send email
    mail($to, $body, $email);
    header( "Location: http://www.webhotdesign.co.uk/whd/pages/thanks.htm" );
    ?>



    <form name="form" id="form" method="post" action="form.php">
    <!--DWLayoutTable-->
    <tr>
    <td width="32" rowspan="9" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td height="66" colspan="2" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="1"></td>
    <td width="26">&nbsp;</td>
    <td width="334">&nbsp;</td>
    <td width="106">&nbsp;</td>
    </tr>
    <tr>
    <td width="69" height="21" valign="top">name<br> </td>
    <td colspan="2" rowspan="8" valign="top"> <p>
    <input name="name" type="text" id="name" size="15" maxlength="20" />
    <br>
    <br>
    <input name="phone" type="text" id="phone" size="15" maxlength="20" />
    <br>
    <br>
    <input name="email" type="text" id="email" size="15" maxlength="25" />
    <br>
    <br>
    <textarea name="message" cols="15" rows="4" wrap="VIRTUAL"></textarea>
    </p>
    <p>
    <input class=aceButton type="submit" value="submit">
    </td>
    <td>&nbsp;</td>
    <td rowspan="4" valign="top"> For all initial enquiries please use the form
    <br><br> Tel: 07782 216 212 <br>
    Email <a href="mailto:enrique@webhotdesign.co.uk">enrique@w ebhotdesign.co.uk</a>
    </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height="20" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height="21" valign="top">phone</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td rowspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td height="14"></td>
    <td></td>
    </tr>
    <tr>
    <td height="6"></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td height="21" valign="top">email</td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td height="20" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td height="164" valign="top"><br>
    message</td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td height="1"></td>
    <td></td>
    <td width="182"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr></form>
    </table>
    Last edited by enrique; 30-11-2006 at 05:39 PM.


  2. #2
    jamey is offline Newbie
    Tackle the Web with $5.99 .COM's from Go Daddy!
    You need a check to ensure that the user has inputted some data before actually sending the email. I have cleaned up your code a bit and here's the result:

    PHP Code:
    <?php

    // Get submitted data
    $name $HTTP_POST_VARS['name'];
    $company 'From: '.$HTTP_POST_VARS['company'];
    $phone $HTTP_POST_VARS['phone'];
    $message $HTTP_POST_VARS['message'];

    // Check all fields have been filled
    if(!empty($name) and !empty($company) and !empty($phone) and !empty($message)) {

        
    // Put data into readable format
        
    $to 'enrique@hotmail.co.uk';
        
    $body 'Name: '.$name.'\n'
        
    .'Company: '.$company.'\n'
        
    .'email: '.$email.'\n'
        
    .'Message: \n \n'.$message;

        
    // Send email
        
    mail($to$body$email);
        
    header('Location: http://webhotdesign.co.uk/whd/pages/thanks.htm');

    }

    ?>

    <form action="<?php print($_SERVER['PHP_SELF']); ?>" method="post">

        <p><label for="name">Name
        <input id="name" maxlength="25" name="name" size="20" type="text" /></label></p>

        <p><label for="phone">Phone
        <input id="phone" maxlength="20" name="phone" size="15" type="text" /></label></p>

        <p><label for="email">Email
        <input id="email" maxlength="100" name="email" size="25" type="text" /></label></p>

        <p><label for="message">Message<br/>
        <textarea cols="50" id="message" name="message" rows="5"></textarea></label></p>

        <input type="submit" value="submit">

    </form>

    <p>For all initial enquiries please use the form.</p>

    <p>Tel: 07782 216 212<br/>
    Email: <a href="mailto:enrique@webhotdesign.co.uk">enrique@webhotdesign.co.uk</a></p>

+ Reply to Thread