Reputation: 21
I started a form in a PHP page and I think I have everything right were it belongs. But when I upload it to a server it doesn’t work. How to fix it?
Here is my code:
<section class="body">
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = '[email protected]';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
<form method="post" action="new.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</section>
so the error that i get is this whole line of code on my live site
Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
Upvotes: 1
Views: 147
Reputation: 6356
It appears that your web server does not support PHP. PHP runs on the web server (aka server side), and the client side (that is the web browser) should only get valid HTML.
It looks like your webserver is not interpreting the PHP. A quick check for this would be to view the source in your browser - if you see PHP code there, then the webserver did not run the PHP.
There are many possible reasons for PHP not being interpreted - the php extension not being handled, PHP not being installed, other web server configurations, etc.
Upvotes: 1