我一直在写电子邮件表格,遇到了一个问题。
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply@YourCompany.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.YourDomain.com/thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
}
}
?> 我试图运行它,但是$name变量一直存在错误。我做了一些研究,发现我也可以使用$$name。我运行了它,但这是行不通的,所以我决定我应该改变脚本的其他部分。我需要知道$name还是$$name。我做了一些研究,发现$$name是一个参考变量,而$name只是一个变量。我需要知道每一个结果是什么,我应该使用哪一个。
发布于 2014-01-22 17:07:30
$$name可能不是你要找的东西
$abc = 'def';
$name = 'abc';
echo $name; // this will output abc
echo $$name; // this will output def您可以从http://www.php.net/manual/en/language.variables.variable.php中阅读有关php变量的信息。
发布于 2014-01-22 17:07:43
它是一个变量:
$x = 'foo';
$foo = 'bar';
$$x = 'baz';
echo "$x $foo"; // outputs 'foo baz', not 'foo bar';$$var基本上是说:“获取$var的内容,并使用该内容作为变量的名称,并分配给该变量”。
发布于 2014-01-22 17:07:23
似乎你想用一个数组
$fields = array();
$fields["Name"] = $_REQUEST['Name'];
$fields["Company"] = $_REQUEST['Company'];
$fields["Email"] = $_REQUEST['Email'];
$fields["Phone"] = $_REQUEST['Phone'];
$fields["Mailing list"] = $_REQUEST['List'];
$fields["Message"] = $_REQUEST["Message"]; 你的剧本现在会很好的。
如果您想包含来自$_REQUEST的数据,请尝试这样做。
您也可以粘贴php表单,我们可以提出一个更优化的解决方案。
https://stackoverflow.com/questions/21289332
复制相似问题