Reputation: 1
I have been self-learning about our office websites over the past couple years and recently our original web person became unable to work on or help with the sites she had set up. Several of our websites have error logs that are filling up from undefined variable notifications. From my research, I believe I need to declare whatever it is giving the error. The example below is from one site with a reference to body. I am a php noob so I appreciate any help. If I add $body = Trim(stripslashes($_POST['body'])); below the human line, will that fix it? I'm afraid to get carried away with changes that might not be necessary since she can't repair any mistake I might make.
PHP Notice: Undefined variable: Body in email.php on line 48
<?php
$emailTo = "[email protected]"; // Email address you want submitted forms to go to
$Subject = "Email Inquiry"; // subject line for emails
$name = Trim(stripslashes($_POST['name']));
$phone = Trim(stripslashes($_POST['phone']));
$email = Trim(stripslashes($_POST['email']));
$mailheader = "From: $email \r\n";
$message = Trim(stripslashes($_POST['message']));
$human = Trim(stripslashes($_POST['human']));
// prepare email body text
$Body .= "Name: "; (this is line 48)
$Body .= $name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
Upvotes: 0
Views: 497
Reputation: 139
This case.. Need to define the variable $Body before you doing String Concatenation.
// prepare email body text
$Body = ''; // define first
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
Upvotes: 1