Php 错误日志在联系人表单中向我抛出一个未识别的索引
我正在处理的网页上的联系人表单出现错误。下面是代码和错误日志。有什么想法吗Php 错误日志在联系人表单中向我抛出一个未识别的索引,php,Php,我正在处理的网页上的联系人表单出现错误。下面是代码和错误日志。有什么想法吗 <?php function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); return html_entity_decode($str,null,'ISO-8859-1');; } function mail_utf8($to, $subjec
<?php
function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); return html_entity_decode($str,null,'ISO-8859-1');; }
function mail_utf8($to, $subject = '(No subject)', $message, $headers) {
$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";
return mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $headers);
}
//function mail_utf8html($to, $subject = '(No subject)', $message, $headers) {
//$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
//return mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $headers);
//}
$stackid = trim($_POST['stackid']);
$cleanowneremail = include(dirname(__FILE__) . '/../'.$stackid.'config_e.php');
$emaillabel = strip_tags($_POST['emaillabel']);
$namelabel = strip_tags($_POST['namelabel']);
$subjectlabel = strip_tags($_POST['subjectlabel']);
$messagelabel = strip_tags($_POST['messagelabel']);
$mail = $_POST['mail'];
$name = strip_tags($_POST['name']);
$subject = strip_tags($_POST['subject']);
$text = trim($_POST['text']);
$text = utf8_urldecode($text);
//$text = stripslashes($text);
//$owneremail = $_POST['owneremail'];
//$cleanowneremail = substr($owneremail, 7); // removes "obscure"
$recipientEmail = explode(',', $cleanowneremail);
foreach($recipientEmail as $value) {
$to = trim($value);
$subject = stripslashes($subject);
$message = trim($emaillabel)." : ".trim($mail)."\n".trim($namelabel)." : ".trim($name)."\n".trim($subjectlabel)." : ".trim($subject)."\n ".trim($messagelabel)." : ".$text."\n\nForm = ".trim($_POST['formname']);
$message = stripslashes($message);
if(trim($_POST['compatibility']) == "true"){
$headers = "From: " . $cleanowneremail . "\n";
}else{
$headers = "From: " . $mail . "\n";
}
$headers .= "Reply-To: ". $mail . "\n";
if(mail_utf8($to,$subject,$message,$headers)){
echo "success"; // we should get this echoed back
}
else{
echo "error";
}
}
$autoreply = trim($_POST['autoreply']);
$autoreply = utf8_urldecode($autoreply);
$autoreplysig = $_POST['autoreplysig']; // if auto reply is selected in the stack
$autoreplysub = $_POST['autosubject'];
if($autoreply != "noreply"){
$autoreplysig = utf8_urldecode($autoreplysig);
$autoreply = stripslashes($autoreply)."<br /><br />".stripslashes($autoreplysig);
//$autoreply .= "<br /><br />Your Message : ".$text;
$autoreplysubject = utf8_urldecode($autoreplysub);
$headers = "From: " . $cleanowneremail . "\r\n";
$headers .= "Reply-To: ". $cleanowneremail . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($mail,$autoreplysubject,$autoreply,$headers);
}
?>
错误日志
- [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:stackid in
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第15行 - [22-Jan-2020 20:28:14 UTC]PHP警告:
包括(/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/。/config_e.php): 无法打开流:在
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第16行 - [22-Jan-2020 20:28:14 UTC]PHP警告:包含():打开失败
“/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/。/config_e.php”
在
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第16行 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:
电子邮件标签位于
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第19行 - [22-Jan-2020 20:28:14 UTC]PHP注意:未定义索引:名称标签
在
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第20行 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 在线21 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:
消息标签位于
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第22行 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:formname
在
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第41行 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:
在中的兼容性
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 在线43 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:自动回复
在
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 在线60 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:
自动重新登录
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第62行 - [22-Jan-2020 20:28:14 UTC]PHP通知:未定义索引:
自动主体插入
/home/e5z2aaq161fd/public_html/contactus/files/contactAssets/contactform.php 第63行
if (isset($_POST['stackid']) && isset($_POST['emaillabel']) && isset($_POST['namelabel']) && isset($_POST['subjectlabel']) && isset($_POST['messagelabel']) && isset($_POST['mail']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['text'])) {
// all your php code here
}
$emaillabel = isset($_POST['emaillabel']) ? strip_tags($_POST['emaillabel']) : '';
$namelabel = isset($_POST['namelabel']) ? strip_tags($_POST['namelabel']) : '';
$subjectlabel = isset($_POST['subjectlabel']) ? trip_tags($_POST['subjectlabel']) : '';
$messagelabel = isset($_POST['messagelabel']) ? strip_tags($_POST['messagelabel']) : '';
// ...etc...
if
语句中,然后在声明其他变量时,只需检查是否首先设置了$\u POST值,如果没有,则将var设置为空字符串错误是显而易见的。您正在尝试访问一个不存在的索引。您不能盲目地认为每次向脚本发出请求时,
$\u POST
必然包含您期望的索引。使用isset()
首先检查它们是否存在,然后再尝试使用它们。谢谢您的输入。我真的是新的php,将检查出来!您也可以试试!empty()
这是否回答了您的问题?对另一个用户已经给了我很好的提示。您的链接仍然是感谢的,因为它更深入地解决不明索引。感谢您的详细回答。我编辑了相关代码,以包括错误日志中显示的其他行。我决定按照您的逻辑,在我的代码副本上尝试第二个选项。稍后将更新以查看任何更改。