简体   繁体   中英

Why is only half of my form sent?

I am trying to use post to send a form to my email address. It is kind of working, I am getting the name and message. Someone helped me with the part that is working, but when I try to add to it, what I added is not sent.

I added a phone number and bid to it. That is the first one below. I tried something else, I have seen something on here as well that did not work at all.

<form action="myform.php" method="POST">
    <p>Name</p> <input type="text" name="name">
    <p>Email</p> <input type="text" name="email">
    <p>Phone number</p> <input type="text" name="phone">
    <p>Your bid</p> <input type="text" name="bid">
    <p>Message</p>
    <textarea style="width:475px; height:175px;margin-left:7%"  name="message"></textarea><br/>
    <input type="submit" value="Send"><input type="reset" value="Clear">
</form>

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message']; //line 5 $message now set
$phone = $_POST['phone'];
$bid = $_POST['bid'];
$formcontent="From: $name \n Message: $message" \n Phone  number:  $phone \n Your bid: $bid";
$recipient = "myemail";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";

update this is what i have http://jsfiddle.net/k8U3r/

I tried this too:

<?php

$name = $_POST['name']; //required
$phone = $_POST['phone']; //required
$bid = $_POST['bid']; //required
$message = $_POST['message']; //required


$formcontent .= " Name: $name \n";
$formcontent .= "Email Address: $email \n";
$formcontent .= "Phone Number: $phone \r\n";
$formcontent .= "Bid: $bid \n";
$formcontent .= " Message: $message \n";
$recipient = "myemail.com";
?>

You have incorrect syntax. The formcontent line should be

$formcontent = "From: $name \n Message: $message \n Phone  number:  $phone \n Your bid: $bid";

You just need to remove the extra quote:

$formcontent="From: $name \n Message: $message" \n Phone  number:  $phone \n Your bid: $bid";                                            
                                              ^

UPDATE: Another fix based on comments below:

You need to define the PHP tags, otherwise it will interpret the php as HTML and just print it out.

    ...
    <textarea style="width:475px; height:175px;margin-left:7%"  name="message"></textarea><br/>
    <input type="submit" value="Send"><input type="reset" value="Clear">
</form>

<?php // Tag here

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message']; //line 5 $message now set
$phone = $_POST['phone'];
$bid = $_POST['bid'];
$formcontent="From: $name \n Message: $message \n Phone  number:  $phone \n Your bid: $bid";
$recipient = "myemail";

?> // And here

in your first code, the $phone and $bid variables are not defined.

$phone = $_POST['phone'];
$bid = $_POST['bid'];

And you should remove the " after $message variable in line 14. Don't forget to check if your form data is set or you will encounter Undefined Variable Error Message . like this:

<?php

if ( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['bid']) $& isset($_POST['message']) ) {
    // Send data...
}

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM