Php 为什么在提交此表格时,电子邮件正文中没有任何内容?

Php 为什么在提交此表格时,电子邮件正文中没有任何内容?,php,html,Php,Html,我的PHP代码: $myemail = myemail; $subject = "success"; if(isset($_POST['firstname'])){ $name = $_POST['firstname']; } if(isset($_POST['lastname'])){ $price = $_POST['lastname']; } $message = "$firstname $lastname"; mail($myemail, $subject, $message);

我的PHP代码:

$myemail = myemail;
$subject = "success";
if(isset($_POST['firstname'])){ $name = $_POST['firstname']; } 
if(isset($_POST['lastname'])){ $price = $_POST['lastname']; } 

$message = "$firstname $lastname";
mail($myemail, $subject, $message);
使用twitter引导的我的html:

<form class="form-horizontal" name="application" method="POST" action="submission.php">
<legend></legend>
<div class="control-group">
<label class="control-label" for="firstname">First Name</label>
<div class="controls">
<input type="text" id="firstname" name="firstname" placeholder="First Name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="lastname">Last Name</label>
<div class="controls">
<input type="text" id="lastname" name="lastname" placeholder="Last Name">
<button type="submit" class="btn btn-success" id="submit">Submit</button>
</div>
</div>
</form>

名字
姓
提交

我收到了电子邮件,但正文中没有任何内容。

您使用了错误的变量<代码>$name和
$price
在:

$name  = $_POST['firstname']; // should be $firstname
$price = $_POST['lastname']; // should be $lastname
&结合:

$message = "$firstname $lastname";
将其更改为:

$firstname = $_POST['firstname'];
$lastname  = $_POST['lastname'];

或,使用
$message=“$name$price”同时保留其余代码的完整性。无论哪种方式,变量都需要匹配,并在整个代码执行过程中保持一致

使用错误报告:

这将表明一个未定义的索引错误


附加说明:

您的代码不包含额外的头,尤其是来自:
头,它可能会被许多服务器拒绝,或者最终被拒绝

使用正确的邮件标题:

根据文件:

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
if(isset($_POST['firstname']){$name=$_POST['firstname'];} 如果(isset($_POST['lastname']){$price=$_POST['lastname'];}

$message=“$firstname$lastname”

你一定是在开玩笑。 $name=。。。 $price=。。。 …“$firstname$lastname”
没有分配给$firstname/$lastname变量的值,可能改用“$name$price”?

您正在将POST变量提取到
$name
$price
中,但将
$firstname
和$
lastname
放在电子邮件中;“别(太用力)打他,”约翰罗德