0

having issues creating a simple working form, the html is all below, followed by the php. I have tried to find a decent yet simple tut for php forms but never found one which is crystal clear.

<form class="form-horizontal" method="post" action="mail.php">
                    <div class="control-group">
                        <label class="control-label" for="name">Name:</label>
                        <div class="controls">
                            <input class="input-xlarge" type="text" id="name" name="name">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="email">Email:</label>
                        <div class="controls">
                            <input class="input-xlarge" type="text" id="email" name="email">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="number">Number:</label>
                        <div class="controls">
                            <input class="input-xlarge" type="text" id="number" name="number">
                        </div>
                    </div>
                    <div class="controls">
                        <textarea class="input-xlarge" rows="6" id="message" name="message"></textarea>
                    </div>
                    <div class="controls">
                        <button class="btn btn-small btn-primary" id="send-mail-btn" type="submit">Send Message!</button>
                    </div>
                </form>

with the following php

<? php

//import of user info
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];

//mail input
$from = 'From: MissMoneyPenny.uk.com'
$to = 'paul@pb84.com';
$subject = 'Enquiry from Website'

//email content
$body = "From: $name\n E-Mail: $email\n Number: $number\n Message: $message";

//send mail
mail ($to, $subject, $body, $from);

?>

But when running the form i get an error on line 4 with is the $name = $_POST['name']; any ideas?

4

4 回答 4

3
<? php
  ^

No space there. That isn't right. it is getting interpreted as a short script-open tag <? followed by php which isn't a valid token there.

于 2012-11-05T10:54:04.423 回答
0

Please try this

Put the assignments(=) in if loop

<?php

    //import of user info

    if($_REQUEST['submit'])
    {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $number = $_POST['number'];
    $message = $_POST['message'];
    }

    //mail input
    $from = 'From: MissMoneyPenny.uk.com'
    $to = 'paul@pb84.com';
    $subject = 'Enquiry from Website'

    //email content
    $body = "From: $name\n E-Mail: $email\n Number: $number\n Message: $message";

    //send mail
    mail ($to, $subject, $body, $from);

    ?>

Also

<?php

use this on starting

于 2012-11-05T11:08:49.777 回答
0

Should it be <?php instead of <? php? Or is that too basic...

于 2012-11-05T10:54:43.047 回答
-1

在 html 输入表单中尝试不同的名称,因为 id 和 name 在 html 输入表单中是相同的,所以请尝试不同的名称。例如,名称:和 mail.php。您可以通过以下方式获得价值,

$name = $_POST['txtName'];

于 2012-11-05T11:03:15.380 回答