0

我正在尝试使用 post 将表格发送到我的电子邮件地址。这是一种工作,我得到了名字和信息。有人帮助我完成了正在工作的部分,但是当我尝试添加它时,我添加的内容没有发送。

我添加了一个电话号码并出价。也就是下面的第一个。我尝试了其他东西,我在这里也看到了一些根本不起作用的东西。

<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!";

更新这就是我所拥有的 http://jsfiddle.net/k8U3r/

我也试过这个:

<?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";
?>
4

2 回答 2

6

您的语法不正确。该formcontent行应该是

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

您只需要删除额外的报价:

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

更新:基于以下评论的另一个修复:

您需要定义 PHP 标签,否则它会将 php 解释为 HTML 并打印出来。

    ...
    <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
于 2013-08-13T20:27:22.737 回答
0

在您的第一个代码中,未定义$phoneand变量。$bid

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

并且您应该删除第 14 行中的"after$message变量。不要忘记检查您的表单数据是否已设置,否则您将遇到Undefined Variable Error Message. 像这样:

<?php

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

?>
于 2013-08-13T20:37:05.183 回答