Reputation: 1340
I made a form to email the data to an email ID. But upon filling up the form and submitting, the browser is saying:
Server error. The website encountered an error while retrieving
http://localhost/process.php
.
Here is the code:
<html>
<head>
<title>Form</title>
</head>
<body>
<form method = "post" action = "process.php">
Enter your name <input type = "text" name = "namee" id = "namee" value = "enter your name" />
Enter your phone number <input type = "text" name = "phone" id = "phone" />
<br>
<input type = "submit" value = "post it!" />
</form>
</body>
</html>
<?php
$person_name = $_POST["namee"];
$person_number = $_POST["phone"];
$to = "[email protected]";
$subject = "form filled up";
$body = $person_name. "<br>" $person_number . "<br>" . $person_name ;
mail($to, $subject, $body);
echo "Thank you!" ;
?>
What is the error??
Upvotes: 1
Views: 151
Reputation: 74217
In order to format email properly, headers using text/html
must be used for <br>
as line breaks.
Otherwise, your email body will appear as John Doe<br>213-555-0123<br>etc.
Plus, as the others have already stated, a missing concatenate in:
$body = $person_name. "<br>" $person_number . "<br>" . $person_name ;
which should read as:
$body = $person_name. "<br>" . $person_number . "<br>" . $person_name;
<?php
$person_name = $_POST["namee"];
$person_number = $_POST["phone"];
$to = "[email protected]";
$subject = "form filled up";
$from="[email protected]";
$body = $person_name. "<br>" . $person_number . "<br>" . $person_name;
$header = 'MIME-Version: 1.0' . "\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: ". $from . " $from " . "\r\n";
mail($to, $subject, $body, $header);
echo "Thank you!";
?>
Upvotes: 1
Reputation: 59
Like it's already said you missed a concatenation dot but I also see another error.
"<br>"
is HTML and without the right content type you won't be able to show HTML in your email.
Take a look at http://php.net/manual/en/function.mail.php for more information and examples.
OR use \n for newlines.
Upvotes: 1
Reputation: 449
There's a syntax error here.
$body = $person_name. "<br>" $person_number . "<br>" . $person_name ;
"<br>"
needs to be followed by a concatenation dot, like so:
$body = $person_name. "<br>" . $person_number . "<br>" . $person_name ;
While developing, you'll want to enable displaying php errors though. Have a look at PHP Runtime Configuration.
Upvotes: 1
Reputation: 16061
$body = $person_name. "<br>" $person_number . "<br>" . $person_name ;
This line is wrong, you're missing a concatenator.
$body = $person_name. "<br>" . $person_number . "<br>" . $person_name ;
Upvotes: 2