Because you are trying to append to an undeclared string in $email_content
& $header
.
On your first lines of each variable change the .=
to =
Question
I have a contact form that is working at the moment,i only get two notices:
Notice: Undefined variable: email_content Notice: Undefined variable: header
This is the code
// check if an error was found - if there was, send the user back to the form
if (isset($error)) {
$_POST['e'] = $error;
} else {
// write the email content <-- HERE IS WHERE THE ERROR OCCURS
$email_content .= "Naam:" . htmlspecialchars($name, ENT_QUOTES) . "\n\n";
$email_content .= "Tel:" . htmlspecialchars($tel, ENT_QUOTES) . "\n\n";
$email_content .= "E-mail:" . htmlspecialchars($email_address, ENT_QUOTES) . "\n\n";
$email_content .= "Onderwerp:" . htmlspecialchars($onderwerp, ENT_QUOTES) . "\n\n";
$email_content .= "Bericht:" . htmlspecialchars($message, ENT_QUOTES) . "\n\n";
/*
$email_content .= "Naam:$name\n\n";
$email_content .= "Tel:$tel\n\n";
$email_content .= "E-mail:$email_address\n\n";
$email_content .= "Onderwerp:$onderwerp\n\n";
$email_content .= "Bericht:$message\n\n";
*/
$header .= 'From: www.UTI.nl'; <-- AND HERE IS ALSO WHERE THE ERROR OCCURS
// send the email
mail ("robin2609@gmail.com", "Nieuw bericht van de UTI website", $email_content, $header ); <-- this is
// send the user back to the form
$_POST['s'] = 'Bedankt voor uw bericht.';
What am i missing? I hope you guys can help me.
Kind regards,
Robin
Solution 3
Because you are trying to append to an undeclared string in $email_content
& $header
.
On your first lines of each variable change the .=
to =
OTHER TIPS
You concatenate a string to an undefined variable:
$email_content .= "....";
Define it first by assigning something to it:
$email_content = "";
$email_content .= "....";
You're using .=
(append string operand) on a string you didn't define yet. PHP sees this:
$string .= $string2
To mean this:
$string = $string . $string2
When it tries to parse that, $string
doesn't exist so can't be concatenated with $string2
or assigned to $string
.
You should replace these lines:
$email_content .= "Naam:" . htmlspecialchars($name, ENT_QUOTES) . "\n\n";
...
$header .= 'From: www.UTI.nl'; <-- AND HERE IS ALSO WHERE THE ERROR OCCURS
With the following:
$email_content = "Naam:" . htmlspecialchars($name, ENT_QUOTES) . "\n\n";
...
$header = 'From: www.UTI.nl';
This should be fine.
You append a String to a undefined Variable. Write
$header = "";
$email_content = "";
before you append sth. You would get an error in other languages.
You are using this in your first line
$email_content .= "Naam:" . htmlspecialchars($name, ENT_QUOTES) . "\n\n";
Which is interpreted as
$email_content = $email_content . "Naam:" . htmlspecialchars($name, ENT_QUOTES) . "\n\n";
SO it says undefined variable.
Remove '.' from the first lines of email_content and header variable
Might help!!
You should initialize this variables. For example, in first lines.
$header = '';
$email_content = '';