I'm just trying to clean up these error logs. I have a form on my site, that WORKS. But my error logs are still showing the undefined indexes. I checked this question, PHP - Notice: Undefined index:, and I think it's what I need but I'm not sure how to implement it to stop sending errors. Again, the form does work, so then why am I getting these errors and how do I stop them.
Note*: If it's a duplicate then comment me, please don't mark it. I see this question as being different since it's not preventing my code from working. I just want to get rid of the errors because it makes no sense how the error code works.
Errors:
[14-Sep-2015 14:40:41 UTC] PHP Notice: Undefined variable: MSG in /home/seenserv/public_html/contact.php on line 134
[14-Sep-2015 14:40:41 UTC] PHP Warning: implode(): Invalid arguments passed in /home/seenserv/public_html/contact.php on line 47
[14-Sep-2015 14:40:41 UTC] PHP Notice: Undefined index: name in /home/seenserv/public_html/contact.php on line 138
[14-Sep-2015 14:40:41 UTC] PHP Notice: Undefined index: phone in /home/seenserv/public_html/contact.php on line 139
[14-Sep-2015 14:40:41 UTC] PHP Notice: Undefined index: email in /home/seenserv/public_html/contact.php on line 140
[14-Sep-2015 14:40:41 UTC] PHP Notice: Undefined index: invoice in /home/seenserv/public_html/contact.php on line 141
[14-Sep-2015 14:40:41 UTC] PHP Notice: Undefined index: comments in /home/seenserv/public_html/contact.php on line 142
FORM:
<form method="post" action="">
<input type="text" name="name" placeholder="*Name" value="<?php echo $_POST['name']; ?>">
<input type="tel" name="phone" placeholder="*Phone Number" value="<?php echo $_POST['phone']; ?>">
<input type="email" name="email" placeholder="*Email" value="<?php echo $_POST['email']; ?>">
<input type="text" name="invoice" placeholder="Invoice Number (optional)" value="<?php echo $_POST['invoice']; ?>">
<textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="*Please enter your comments here..."><?php echo htmlentities($_POST['comments'], ENT_COMPAT,'ISO-8859-1', true);?></textarea>
<button type="submit">Submit</button>
</form>
PHP Form functions:
if(!array_filter($MSG)){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$MSG[] = "Invalid Email Format (test@provider.com)";
}
else{
$POST['invoice'] = $invoice['invoice'];
if(send_mail($POST)){
header('Location: messageSent.php');
}
else{
$MSG[] = "Email Failed. Please Try Again.";
}
}
}
}
function filter_post($POST){
$keys = array('name','phone','email','invoice','comments');
$POST = array_intersect_key($POST, array_flip($keys));
$POST = array_map('strip_tags', $POST);
return($POST);
}
function check_empty($POST){
foreach($POST as $key => $value){
if(empty($value)){
$MSG[] = "You need to fill out the $key section";
}
}
return($MSG);
}
function send_mail($POST){
extract($POST);
$to = '7servicerepairs@gmail.com';
$sbj = 'New Question For Se7en Service!';
$msg = "Name: $name \n Phone: $phone \n Email: $email \n Invoice #: $invoice \n Comments: $comments";
$headers = "From: Se7en Service Customer Care <7servicerepairs@gmail.com>\r\n";
$headers .="Reply-To: $email";
return(mail($to, $sbj, $msg, $headers));
}
function output_errors($MSG){
return '<ul><li>' . implode('</li><li>', $MSG) . '</li></ul>';
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>