gpt4 book ai didi

PHP从html表单传递参数

转载 作者:太空宇宙 更新时间:2023-11-04 14:37:50 25 4
gpt4 key购买 nike

我来自 C# 背景,我是 php 的新手,我有一个 html 表单将它的值提交到以下 php 文件,但由于某种原因没有设置值,我做错了什么?

<?php
include('Mail.php');
$recipients = "myemail@hotmail.com";
$name = $_POST["txtName"] ;
$from = $_POST["txtEmail"] ;
$subject = $_POST["txtAppName"] ;
$comments = $_POST["txtComment"] ;

$headers = array (
'From' => $from,
'To' => $recipients,
'Subject' => $subject,
);
$body = "Name: ".$name."\r\n"."Comments: "."\r\n".$comments;
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'username',
'password' => 'pass', # As set on your project's config page
'debug' => true, # uncomment to enable debugging
));
$mail_object->send($recipients, $headers, $body);
?>

这是 html 表单:

<form action="sendfeedback.php" method="post">
<div><input placeholder="Name" id="txtName" type="text" /></div>
<div><input placeholder="Email (Optional)" id="txtEmail" type="text" /></div>
<div><input placeholder="Application Name (Type in the application name you're using)" id="txtAppName" type="text" /></div>
<div style="height:4px"></div>
<div><textarea placeholder="Comments..." id="txtComment"></textarea></div>
<div style="width:407px; text-align:right;"><input id="submitComment" type="submit" value="Send" /></div>
</form>

最佳答案

您的表单输入应具有属性 name,如下所示:

<form action="sendfeedback.php" method="post">
<div><input placeholder="Name" id="txtName" name='txtName' type="text" /></div>
<div><input placeholder="Email (Optional)" id="txtEmail" name="txtEmail" type="text" /></div>
<div><input placeholder="Application Name (Type in the application name you're using)" id="txtAppName" name="txtAppName" type="text" /></div>
<div style="height:4px"></div>
<div><textarea placeholder="Comments..." id="txtComment" name='txtComment'></textarea></div>
<div style="width:407px; text-align:right;"><input id="submitComment" type="submit" value="Send" /></div>
</form>

关于PHP从html表单传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21996711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com