I ran into a problem when trying to code along to this video tutorial on Beginner level PHP. I am having problems getting it to work for me. I get this error that states the problem is in line 44 of my code in the mailprocess.php file when I try loading the project in the browser. Line 44 of my code that this error is pertaining to is the beginning of an if statement: if (isset($$item) && !$empty($$item))
But when the instructor doing the video tutorial does this same thing, it works fine for him. So I don't understand why it's not working for me. I am also having problems getting the hang of getting my copy/pasted code to format correctly in the code block format tool here in order to post it, so please bear with me if it's not aligned perfectly as I am new and really struggling trying to learn and I am finding PHP to be rather difficult. Any help at all to get this to work for me would be greatly appreciated.
Here is the browser output of the error I am getting:
Here is my mailprocess.php file and code:
<?php
$suspect = false;
$pattern = '/Content-Type:|Bcc:|Cc:/i'; //Perl compatible reg-x to filter
$empty = false;
function isSupect($val, $pattern, &$suspect) {
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}else {
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
isSuspect($_POST, $pattern, $suspect);
}
if (!$suspect) {
foreach ($_POST as $key => $value) {
$temp = is_array($value) ? $value : trim($value); //removes white space
if (empty($temp) && in_array($key, $required)) {
$missing[] = $key;
$$key = '';
} elseif (in_array($key, $expected)) {
$$key = $temp;
}
}
}
if (!$suspect && !$empty['$email']) {
$validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($validemail) {
$headers .= "
Reply-to: $validemail";
} else {
$errors['email'] = true;
}
}
if (!$suspect && !$missing && !$errors){
$message = ' ';
foreach ($expected as $item) {
if (isset($$item) && !$empty($$item)){
$val = $$item;
} else {
$val = 'Not selected';
}
if (is_array($val)){
$val = implode(', ', $val);
}
$item = str_replace(array('_', '-'), '', $item);
$message .= ucfirst($item) . ": $val
";
}
$message = wordwrap($message, 70);
$mailSent = true;
}
And here is what the instructor has in his code: